From c3be703a20f524aed19d1b19105c7660b102d2b8 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Tue, 31 Mar 2020 15:03:09 +0000 Subject: [PATCH] DataBeam : - aggiornamenti e correzioni varie. --- ClearProcess.lua | 4 +- LuaLibs/BeamExec.lua | 2 +- LuaLibs/ProcessBlockHausFront.lua | 12 +- LuaLibs/ProcessDrill.lua | 5 +- LuaLibs/ProcessDtMortise.lua | 213 ++++--- LuaLibs/ProcessLapJoint.lua | 996 +++++++++++++++++++++++------- 6 files changed, 912 insertions(+), 320 deletions(-) diff --git a/ClearProcess.lua b/ClearProcess.lua index dc86eed..63072cc 100644 --- a/ClearProcess.lua +++ b/ClearProcess.lua @@ -1,4 +1,4 @@ --- ClearProcess.lua by Egaltech s.r.l. 2019/01/10 +-- ClearProcess.lua by Egaltech s.r.l. 2020/03/30 -- Se la trave non è parte di un gruppo di lavoro, cancello geometrie aggiunte -- Intestazioni @@ -44,7 +44,7 @@ end local LayId = EgtGetFirstLayer( PartId) while LayId do local NextLayId = EgtGetNextLayer( LayId) - if EgtGetInfo( LayId, '!MGO') then + if EgtGetInfo( LayId, GDB_SI.MGRPONLY) then EgtErase( LayId) end LayId = NextLayId diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index 06725bb..eec3b5c 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -519,7 +519,7 @@ local function ClassifyFeatures( vProc, b3Raw, Stats) -- se mezzo-legno di testa elseif RidgeLap.Identify( Proc) then bOk, bDown = RidgeLap.Classify( Proc) - -- se mezzo-legno, fessura, fessura frontale, notch, tasca, tacca + -- se mezzo-legno, fessura, fessura frontale, notch, tasca, tacca, taglio a triangolo elseif LapJoint.Identify( Proc) then bOk, bDown = LapJoint.Classify( Proc) -- se foratura diff --git a/LuaLibs/ProcessBlockHausFront.lua b/LuaLibs/ProcessBlockHausFront.lua index 93b53db..3b9c067 100644 --- a/LuaLibs/ProcessBlockHausFront.lua +++ b/LuaLibs/ProcessBlockHausFront.lua @@ -1,4 +1,4 @@ --- ProcessBlockHausFront.lua by Egaltech s.r.l. 2020/02/11 +-- ProcessBlockHausFront.lua by Egaltech s.r.l. 2020/03/30 -- Gestione calcolo giunzione block house in testa -- Tabella per definizione modulo @@ -32,7 +32,7 @@ function ProcessBlockHausFront.Classify( Proc) -- se versore z è preponderante sulle altre componenti del vettore ed è verso il basso, -- do errore perchè non è ancora gestita la rotazione di 90° -- considerazioni: al momento non è possibile sapere se ci sono due rastremature o una quindi se è rivolta verso il basso - -- viene dato errore, altrimenti si porebbe imporre la rotazione di 180 (ovviamente con una sola rastrematura rivolta verso il basso) + -- viene dato errore, altrimenti si potrebbe imporre la rotazione di 180 (ovviamente con una sola rastrematura rivolta verso il basso) if abs(vtN:getZ()) > abs(vtN:getX()) and abs(vtN:getZ()) > abs(vtN:getY()) and vtN:getZ() < -0.5 then return false end @@ -117,7 +117,7 @@ function ProcessBlockHausFront.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) dToolThick = EgtTdbGetCurrToolParam(MCH_TP.THICK) or dToolThick end end - -- recupero la geometria opzionale + -- recupero la geometria ausiliaria local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') if AuxId then AuxId = AuxId + Proc.Id end -- recupero gruppo per geometria addizionale @@ -128,7 +128,7 @@ function ProcessBlockHausFront.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) return false, sErr end -- cerco se nelle note del layer c'è già la nota che indica che l'aux è già stato lavorato - local bAuxMachined = EgtGetInfo( nAddGrpId, 'AuxId', 'b') + local bAuxMachined = EgtGetInfo( nAddGrpId, 'AuxId.'..tostring(AuxId or 0), 'b') -- taglio sulla faccia esterna if AuxId and not bAuxMachined then -- in generale va fatto @@ -149,7 +149,7 @@ function ProcessBlockHausFront.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) -- se taglio applicato setto la nota al gruppo Mach per non doverla lavorare una seconda volta if bOk then bAuxMachined = true - EgtSetInfo( nAddGrpId, 'AuxId', true) + EgtSetInfo( nAddGrpId, 'AuxId.'..tostring(AuxId or 0), true) else return bOk, sErr end @@ -240,7 +240,7 @@ function ProcessBlockHausFront.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) -- se taglio applicato setto la nota al gruppo Mach per non doverla lavorare una seconda volta if bOk then bAuxMachined = true - EgtSetInfo( nAddGrpId, 'AuxId', true) + EgtSetInfo( nAddGrpId, 'AuxId.'..tostring(AuxId or 0), true) else return bOk, sErr end diff --git a/LuaLibs/ProcessDrill.lua b/LuaLibs/ProcessDrill.lua index e4c1832..e45a498 100644 --- a/LuaLibs/ProcessDrill.lua +++ b/LuaLibs/ProcessDrill.lua @@ -1,4 +1,4 @@ --- ProcessDrill.lua by Egaltech s.r.l. 2020/03/06 +-- ProcessDrill.lua by Egaltech s.r.l. 2020/03/31 -- Gestione calcolo forature per Travi -- Tabella per definizione modulo @@ -90,7 +90,8 @@ function ProcessDrill.Split( Proc, b3Raw) dMaxMat = 0 end -- restituisco se va fatto in doppio (solo fori orizzontali) - return ( bOpen and dLen > dMaxMat + 10 * GEO.EPS_SMALL and abs( vtExtr:getZ()) < abs( BD.DRILL_VZ_MIN) and + local DRILL_EXTRA = 5 + return ( bOpen and dLen + DRILL_EXTRA > dMaxMat + 10 * GEO.EPS_SMALL and abs( vtExtr:getZ()) < abs( BD.DRILL_VZ_MIN) and ( abs( vtExtr:getY()) * b3Raw:getDimZ() > abs( vtExtr:getZ()) * b3Raw:getDimY() or Proc.Fce == 5 or Proc.Fce == 6)) end diff --git a/LuaLibs/ProcessDtMortise.lua b/LuaLibs/ProcessDtMortise.lua index 42d3330..94fb553 100644 --- a/LuaLibs/ProcessDtMortise.lua +++ b/LuaLibs/ProcessDtMortise.lua @@ -1,4 +1,4 @@ --- ProcessMortise.lua by Egaltech s.r.l. 2020/03/19 +-- ProcessDtMortise.lua by Egaltech s.r.l. 2020/03/31 -- Gestione calcolo mortase a coda di rondice per Travi -- Tabella per definizione modulo @@ -16,6 +16,7 @@ local ML = require( 'MachiningLib') -- settaggi interni ( poi andrà utilizzato parametro ACTIVE_AS proveniente da parametri utente di TechnoEssetre) local bMakeAntiSplitPath = true +local bMakeAsByArc = true --------------------------------------------------------------------- -- Riconoscimento della feature @@ -47,6 +48,57 @@ function ProcessDtMortise.Classify( Proc) return true, bDown end +--------------------------------------------------------------------- +local function ExtractTopPath( nProcId, vtOrtho, nAddGrpId, rfFac0, dZedTop) + + -- estraggo percorso di contorno + local nAuxTop, nNumTop = EgtExtractSurfTmLoops( nProcId, nAddGrpId) + if nNumTop ~= 1 then + -- elimino i percorsi creati + for i = 1, nNumTop do + EgtErase( nAuxTop + i - 1) + end + return nil, 0 + else + -- fondo tra loro le curve compatibili + EgtMergeCurvesInCurveCompo( nAuxTop) + -- esplodo il percorso in modo da avere entità separate per poterle controllare + local nStartId, nCount = EgtExplodeCurveCompo( nAuxTop) + if nStartId then + -- tabella con identificativi delle curve + tEnt = EgtTableFill( nStartId, nCount) + -- elimino le curve che non stanno al bordo superiore + for i = nCount, 1, -1 do + local ptP1 = EgtSP( tEnt[i], GDB_RT.GLOB) + local ptP2 = EgtEP( tEnt[i], GDB_RT.GLOB) + ptP1:toLoc( rfFac0) + ptP2:toLoc( rfFac0) + -- se ha variazioni in Z o non è alla giusta Z, cancello l'entità + if ( abs( ptP1:getZ() - ptP2:getZ()) > 10 * GEO.EPS_SMALL) or + ( abs( ptP1:getZ() - dZedTop) > 10 * GEO.EPS_SMALL) then + EgtErase( tEnt[i]) + table.remove( tEnt, i) + end + end + -- ricreo il percorso + local ptStart = EgtSP( tEnt[1]) + local nFirstId, nCnt = EgtCurveCompoByReorder( nAddGrpId, tEnt, ptStart, true) + if not nFirstId then return nil, 0 end + -- deve rimanere un solo percorso + if nCnt > 1 then + for nId = nFirstId, nFirstId + nCnt - 1 do + EgtErase( nFirstId) + end + return nil, 0 + end + -- modifico estrusione percorso + EgtModifyCurveExtrusion( nFirstId, vtOrtho, GDB_RT.GLOB) + return nFirstId, 1 + end + end + return nil, 0 +end + --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessDtMortise.Make( Proc, nPhase, nRawId, nPartId) @@ -74,96 +126,107 @@ function ProcessDtMortise.Make( Proc, nPhase, nRawId, nPartId) EgtOutLog( sErr) return false, sErr end - -- recupero il diametro dell'utensile + -- recupero il diametro dell'utensile e l'angolo di spoglia local dToolDiam = 100 local dMaxMat = 30 + local dSideAngle = 0 if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam dMaxMat = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxMat + dSideAngle = EgtTdbGetCurrToolParam( MCH_TP.SIDEANG) or dSideAngle end end -- se parametro interno abilitato e il percorso non è chiuso, aggiungo percorso e lavorazione antischeggia if bMakeAntiSplitPath and not EgtCurveIsClosed( AuxId) then - -- recupero punto iniziale e finale del percorso - local pStartP = EgtSP( AuxId, GDB_RT.GLOB) - local pEndP = EgtEP( AuxId, GDB_RT.GLOB) - if pStartP and pEndP then - -- recupero gruppo per geometria addizionale - local nAddGrpId = BL.GetAddGroup( nPartId) - if not nAddGrpId then - local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing AddGroup' - EgtOutLog( sErr) - return false, sErr - end - - local pMid = ( pStartP + pEndP) / 2 - local dDistMid = dist( pStartP, pMid) - local pMidArc - local bGoodArc - local nDiv = 2 - local nId1 - -- ciclo fino ad individuare arco compativile con l'utensile - while not bGoodArc do - -- linea dal punto medio alla fine - nId1 = EgtLine( nAddGrpId, pMid, pEndP, GDB_RT.GLOB) - -- se è stata creata setto il piano e l'accorcio - if nId1 then - -- EgtModifyCurveExtrusion( nId1, vtExtr, GDB_RT.GLOB) - -- accorcio la seconda linea al valore impostato, partendo dal divisore 2 - EgtTrimExtendCurveByLen( nId1, -( dDistMid * ( 1 - ( 1 / nDiv))), pEndP, GDB_RT.GLOB) - -- ruoto di -90 gradi - EgtRotate( nId1, pMid, vtExtr, -90, GDB_RT.GLOB) - -- prendo il punto finale dell'entità ruotata - pMidArc = EgtEP( nId1, GDB_RT.GLOB) - -- cancello linea - EgtErase(nId1) - -- creo arco per 3 punti - nId1 = EgtArc3P( nAddGrpId, pStartP, pMidArc, pEndP, GDB_RT.GLOB) - if nId1 then - EgtModifyCurveExtrusion( nId1, vtExtr, GDB_RT.GLOB) - -- recupero il raggio e lo comparo con il raggio utensile, - -- se è maggiore del raggio utensile esco dal cliclo - local dRad = EgtArcRadius( nId1) - if dRad > 0 and dRad > dToolDiam then - bGoodArc = true - else - -- cancello l'arco e incremento il componente del divisore - EgtErase(nId1) - nDiv = nDiv + 1 - end - else - bGoodArc = true - end + -- recupero il riferimento della faccia di fondo + local rfFac0 = EgtSurfTmFacetMinAreaRectangle( Proc.Id, 0, GDB_ID.ROOT) + -- ottengo il box con la normale della faccia 0 + local bBoxF0 = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, rfFac0) + -- recupero l'altezza della mortasa + local dAltMort = bBoxF0:getDimZ() + -- recupero gruppo per geometria addizionale + local nAddGrpId = BL.GetAddGroup( nPartId) + if not nAddGrpId then + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing AddGroup' + EgtOutLog( sErr) + return false, sErr + end + -- estraggo il percorso top mortise + local nAuxId1 = ExtractTopPath( Proc.Id, vtExtr, nAddGrpId, rfFac0, dAltMort) + -- se esiste il percorso + if nAuxId1 then + -- creo percorso sulla parte alta della mortasa + local dToolRadDelta = dAltMort * tan( dSideAngle) + local dTopDiam = dToolDiam + 2 * dToolRadDelta + -- recupero punto iniziale e finale del percorso + local ptStart = EgtSP( nAuxId1, GDB_RT.GLOB) + local ptEnd = EgtEP( nAuxId1, GDB_RT.GLOB) + if ptStart and ptEnd then + local nId1 + -- se richiesti due segmenti di linea + if not bMakeAsByArc then + -- determino il punto comune dei due segmenti + local vtDelta = ( ptEnd - ptStart) / 4 + vtDelta:rotate( vtExtr, -90) + local ptMid = ( ptStart + ptEnd) / 2 + vtDelta + -- creo la spezzata formata dai due segmenti + nId1 = EgtCurveCompoFromPoints( nAddGrpId, { ptStart, ptMid, ptEnd}, GDB_RT.GLOB) + -- altrimenti richiesto arco else - bGoodArc = true + -- direzione del segmento + local vtDir = ptEnd - ptStart ; + local dLen = vtDir:len() + vtDir:normalize() + -- direzioni tangenti iniziale e finale + local vtStart = EgtSV( nAuxId1, GDB_RT.GLOB) + local vtEnd = EgtEV( nAuxId1, GDB_RT.GLOB) + -- angoli + local dAngStart = acos( vtStart * vtDir) + local dAngEnd = acos( vtEnd * vtDir) + local dMaxAng = min( 30, dAngStart, dAngEnd) + if dLen < dTopDiam then + dMaxAng = min( dMaxAng, asin( dLen / dTopDiam)) + end + local vtTg = vtDir ; vtTg:rotate( vtExtr, -dMaxAng) + -- creo l'arco + nId1 = EgtArc2PV( nAddGrpId, ptStart, ptEnd, vtTg, GDB_RT.GLOB) end - end - if not nId1 then + if not nId1 then + local sErr = 'Wrong geometry : Error on DtMortise ' .. tostring( Proc.Id) + EgtOutLog( sErr) + return false, sErr + end + EgtModifyCurveExtrusion( nId1, vtExtr, GDB_RT.GLOB) + -- inserisco la lavorazione di contornatura anti splint + local sNameF = 'DtMtAS_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + 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( {{ nId1, -1}}) + -- setto affondamento pari all'altezza della mortsasa + EgtSetMachiningParam( MCH_MP.DEPTH, dAltMort) + -- setto offset radiale con aggiunto un ulteriore allargamento di 1mm + EgtSetMachiningParam( MCH_MP.OFFSR, dToolRadDelta - 1) + -- dichiaro non si generano sfridi per VMill + local sUserNotes = 'MaxElev='.. EgtNumToString( dAltMort, 1) .. '; VMRS=0;' + EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchFId, false) + return false, sErr + end + else local sErr = 'Wrong geometry : Error on DtMortise ' .. tostring( Proc.Id) EgtOutLog( sErr) return false, sErr end - -- inserisco la lavorazione di contornatura anti splint - local sNameF = 'DtMtAS_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) - 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( {{ nId1, -1}}) - -- dichiaro non si generano sfridi per VMill - local sUserNotes = 'MaxElev='.. EgtNumToString( dMaxMat - 0.1, 1) .. 'VMRS=0;' - EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes) - -- eseguo - if not EgtApplyMachining( true, false) then - local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchFId, false) - return false, sErr - end else local sErr = 'Wrong geometry : Error on DtMortise ' .. tostring( Proc.Id) EgtOutLog( sErr) @@ -209,7 +272,7 @@ function ProcessDtMortise.Make( Proc, nPhase, nRawId, nPartId) -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- dichiaro non si generano sfridi per VMill - local sUserNotes = 'MaxElev='.. EgtNumToString( dMaxMat - 0.1, 1) .. 'VMRS=0;' + local sUserNotes = 'MaxElev='.. EgtNumToString( dMaxMat - 0.1, 1) .. '; VMRS=0;' EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes) -- eseguo if not EgtApplyMachining( true, false) then diff --git a/LuaLibs/ProcessLapJoint.lua b/LuaLibs/ProcessLapJoint.lua index a553bad..0060390 100644 --- a/LuaLibs/ProcessLapJoint.lua +++ b/LuaLibs/ProcessLapJoint.lua @@ -1,4 +1,4 @@ --- ProcessLapJoint.lua by Egaltech s.r.l. 2020/03/20 +-- ProcessLapJoint.lua by Egaltech s.r.l. 2020/03/31 -- Gestione calcolo mezzo-legno per Travi -- 2019/10/08 Agg. gestione OpenPocket. @@ -48,7 +48,8 @@ function ProcessLapJoint.Identify( Proc) (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 33) or (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 34) or ( Proc.Grp == 4 and Proc.Prc == 37) or - ( Proc.Grp == 4 and Proc.Prc == 39)) + ( Proc.Grp == 4 and Proc.Prc == 39) or + ( Proc.Grp == 4 and Proc.Prc == 120)) end --------------------------------------------------------------------- @@ -160,6 +161,7 @@ local function VerifySawChain( Proc, dMinDim, dMaxDim, vtOrtho) local dMaxMat = 0 local dSawCornerRad = 0 local dSawThick = 0 + local dMaxDepth = 200 -- se non trova una lavorazione di sawing esco if not sSawing then return bUseSawChain @@ -175,13 +177,14 @@ local function VerifySawChain( Proc, dMinDim, dMaxDim, vtOrtho) dSawWidth = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dSawWidth dSawThick = EgtTdbGetCurrToolParam( MCH_TP.THICK) or dSawThick dSawCornerRad = EgtTdbGetCurrToolParam( MCH_TP.CORNRAD) or dSawCornerRad + dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth end if dSawThick <= dMinDim and dSawWidth <= dMaxDim then bUseSawChain = true end end end - return bUseSawChain, sSawing, dMaxMat, dSawCornerRad, dSawThick + return bUseSawChain, sSawing, dMaxMat, dSawCornerRad, dSawThick, dMaxDepth end --------------------------------------------------------------------- @@ -289,8 +292,13 @@ local function GetTunnelDimension( Proc, nPartId) EgtOutLog( sErr) return false, sErr end + -- mi assicuro che la Z del punto utilizzato per creare la superfic sia alla Z media del bounding box locale + local ptN2 = Point3d(ptN1) + ptN2:toLoc(frFc) + ptN2 = Point3d( ptN2:getX(), ptN2:getY(), ( bBoxLoc:getMin():getZ() + bBoxLoc:getMax():getZ())/2) + ptN2:toGlob(frFc) -- creeo superfice intermedia - local nSurfInt = EgtSurfTmPlaneInBBox( nAddGrpId, ptN1, vtOrtho, b3Solid, GDB_ID.ROOT) + local nSurfInt = EgtSurfTmPlaneInBBox( nAddGrpId, ptN2, vtOrtho, b3Solid, GDB_ID.ROOT) -- ritaglio la superfici con le facce della fessura for i = 1, nFacCnt do local ptN, vtN = EgtSurfTmFacetCenter( Proc.Id, i - 1, GDB_ID.ROOT) @@ -675,9 +683,9 @@ local function MakeTwoFacesByMill( Proc, nPhase, nRawId, nPartId) end --------------------------------------------------------------------- -local function MakePreCuts( Proc, nPhase, nRawId, nPartId, b3Raw) +local function MakePreCuts( Proc, nPhase, nRawId, nPartId, b3Raw, nChamfer) -- se interessa l'intera sezione della trave, necessaria sgrossatura - if Proc.Box:getDimY() > 0.9 * b3Raw:getDimY() and Proc.Box:getDimZ() > 0.9 * b3Raw:getDimZ() then + if nChamfer < 2 and Proc.Box:getDimY() > 0.9 * b3Raw:getDimY() and Proc.Box:getDimZ() > 0.9 * b3Raw:getDimZ() then -- recupero gruppo per geometria addizionale local nAddGrpId = BL.GetAddGroup( nPartId) if not nAddGrpId then @@ -789,7 +797,7 @@ local function MakeByMill( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, dH, dV -- Se massimo materiale utensile è molto inferiore dell'elevazione non faccio la lavorazione e do un warning if dMaxMat > 0 and dMaxMat + 15 < dElev then sWarn = 'Warning in process ' .. tostring( Proc.Id) .. ' ,skipped milling; elevation bigger than max tool depth' - return true, sWarn + return true, sWarn, dMaxMat end -- Calcolo uso faccia local nFaceUse = BL.GetNearestParalOpposite( rfFac:getVersZ()) @@ -870,10 +878,10 @@ local function ChooseCorner( Proc, nFacInd) end end if bInsert then - local _, ptP1, ptP2, _ = EgtSurfTmFacetsContact( Proc.Id, vAdj[i], vAdj[j], GDB_ID.ROOT) + local _, ptP1, ptP2, dAng = EgtSurfTmFacetsContact( Proc.Id, vAdj[i], vAdj[j], GDB_ID.ROOT) if ptP1 and ptP2 then local dLen = dist( ptP1, ptP2) - table.insert( tFacAdj, { vAdj[i], vAdj[j], dLen, ptP1, ptP2}) + table.insert( tFacAdj, { vAdj[i], vAdj[j], dLen, ptP1, ptP2, dAng}) end end end @@ -893,6 +901,182 @@ local function ChooseCorner( Proc, nFacInd) return dMaxLen, nIdLine, tFacAdj end +--------------------------------------------------------------------- +local function MakeContourCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacInd, nAddGrpId, dDiam) + + local sMyWarn = '' + local pAuxId = {} + local nAuxId + local AuxId + local ptApPoint + local sMilling + local dTrimDist + local dCollSic = BD.COLL_SIC + + -- ottengo gli angoli dove applicare il percorso con fresa più piccola + local dMaxLen, nIdLine, tFacAdj = ChooseCorner( Proc, nFacInd) + -- prendo il primo versore + local _, vtN1 = EgtSurfTmFacetCenter( Proc.Id, nFacInd, GDB_ID.ROOT) + -- se direzione tende verso una delle alle 3 direzioni azzero l'altezza extra + if abs( vtN1:getX()) > 0.7 or abs( vtN1:getY()) > 0.7 or abs( vtN1:getZ()) > 0.7 then dCollSic = 0 end + + -- se fresatura da sotto salto la lavorazione + if vtN1:getZ() < BD.DRILL_VZ_MIN then + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' milling from bottom ' + EgtOutLog( sErr) + return false, sErr + end + + -- ciclo su tutti gli angoli trovati + for i = 1, #tFacAdj do + sMyWarn = '' + -- le 2 facce di contatto devono essere perpendicolari o non sottossquadra rispetto alla faccia di fondo + -- e ra le due facce deve esserci un angolo interno + local _, ptP1, ptP2, dAng = EgtSurfTmFacetsContact( Proc.Id, nFacInd, tFacAdj[i][1], GDB_ID.ROOT) + local _, ptP1x, ptP2x, dAngx = EgtSurfTmFacetsContact( Proc.Id, nFacInd, tFacAdj[i][2], GDB_ID.ROOT) + if ( dAng < 0 and 180 + dAng >= 90 - 10 * GEO.EPS_SMALL) and ( dAngx < 0 and 180 + dAngx >= 90 - 10 * GEO.EPS_SMALL) and ( tFacAdj[i][6] < 0) then + -- prendo la lunghezza di adiacenza delle due linee + local dLen1 = dist( ptP1, ptP2) + local dLen2 = dist( ptP1x, ptP2x) + -- cerco il punto tra le 3 facce: nIdEndPoint + local nIdIniPoint + local nIdEndPoint + if ptP1 and ptP2 then + if ( dist( ptP1, tFacAdj[i][4]) < GEO.EPS_SMALL) or ( dist( ptP2, tFacAdj[i][4]) < GEO.EPS_SMALL) then + nIdEndPoint = 4 + nIdIniPoint = 5 + elseif ( dist( ptP1, tFacAdj[i][5]) < GEO.EPS_SMALL) or ( dist( ptP2, tFacAdj[i][5]) < GEO.EPS_SMALL) then + nIdEndPoint = 5 + nIdIniPoint = 4 + end + end + -- se ho il punto comune + if nIdEndPoint then + -- recupero la lavorazione con elevazione pari all'altezza trovata + sMilling = ML.FindMilling( 'LongSmallCut', tFacAdj[i][3] + dCollSic) + if sMilling then + -- recupero i dati dell'utensile + local dTDiam = 50 + local dMaxMat = 0 + if EgtMdbSetCurrMachining( sMilling) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + dTDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dTDiam + dMaxMat = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxMat + end + -- se il diametro trovato è minore della metà del diametro utilizzato in precendenza + if dTDiam < ( dDiam / 2) then + -- calcolo lunghezza minima in base all'angolo tra le due pareti + local dMinDist = (( dDiam / 2) / tan( ( 180 + tFacAdj[i][6]) / 2)) + 2 + -- se entrambe le linee sono maggiori delle lunghezza minima proseguo + if dLen1 >= dMinDist and dLen2 >= dMinDist then + -- se il punto finale corrisponde con il punto utilizzato in precedenza, uso l'altro + if dist( tFacAdj[i][nIdEndPoint], ptP1) < 10 * GEO.EPS_SMALL then + ptApPoint = ptP2 + else + ptApPoint = ptP1 + end + -- prima linea + nAuxId = EgtLine( nAddGrpId, ptApPoint, tFacAdj[i][nIdEndPoint], GDB_RT.GLOB) + -- calcolo arretramento + dTrimDist = dLen1 - dMinDist + -- se arretramento valido + if dTrimDist > 100 * GEO.EPS_SMALL then + EgtTrimExtendCurveByLen( nAuxId , - dTrimDist, ptApPoint , GDB_RT.GLOB) + end + table.insert( pAuxId, nAuxId) + -- se il punto finale corrisponde con il punto comune, uso l'altro + if dist( tFacAdj[i][nIdEndPoint], ptP1x) < 10 * GEO.EPS_SMALL then + ptApPoint = ptP2x + else + ptApPoint = ptP1x + end + -- seconda linea + nAuxId = EgtLine( nAddGrpId, tFacAdj[i][nIdEndPoint], ptApPoint, GDB_RT.GLOB) + -- calcolo arretramento + dTrimDist = dLen2 - dMinDist + -- se arretramento valido + if dTrimDist > 100 * GEO.EPS_SMALL then + EgtTrimExtendCurveByLen( nAuxId , - dTrimDist, ptApPoint , GDB_RT.GLOB) + end + table.insert( pAuxId, nAuxId) + -- trasformo in percorso + if #pAuxId > 0 then + AuxId = EgtCurveCompo( nAddGrpId, pAuxId, true) + end + -- se c'è il percorso + if AuxId then + -- modifico versore direzione + EgtModifyCurveExtrusion( AuxId, vtN1, GDB_RT.GLOB) + -- inserisco la lavorazione + local sName = 'Clean_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + local nMchId = EgtAddMachining( sName, sMilling) + if nMchId then + -- aggiungo geometria + EgtSetMachiningGeometry( {{ AuxId, -1}}) + -- imposto posizione braccio porta testa + local nSCC = MCH_SCC.ADIR_YM + if vtN1:getY() > 100 * GEO.EPS_ZERO then + nSCC = MCH_SCC.ADIR_YP + end + EgtSetMachiningParam( MCH_MP.SCC, nSCC) + EgtSetMachiningParam( MCH_MP.LEADINTYPE, 0) + EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 4) + -- allungo inizio e fine di 0mm + EgtSetMachiningParam( MCH_MP.STARTADDLEN, 0) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, 0) + -- setto affondamento 0 + EgtSetMachiningParam( MCH_MP.DEPTH, 0) + -- setto non inversione del percorso + EgtSetMachiningParam( MCH_MP.INVERT, false) + -- Note utente con dichiarazione nessuna generazione sfridi per Vmill + local sUserNotes = 'VMRS=0;' + -- aggiungo alle note massima elevazione + sUserNotes = sUserNotes .. 'MaxElev=' .. EgtNumToString( tFacAdj[i][3], 1) .. ';' + EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes) + if EgtApplyMachining( true, false) then + _, sMyWarn = EgtGetMachMgrWarning( 0) + if EgtIsMachiningEmpty() then + EgtSetOperationMode( nMchId, false) + end + -- altrimenti lavorazione non applicata + else + _, sMyWarn = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchId, false) + end + -- altrimenti non è ctata inserita lavorazione + else + sMyWarn = 'warning adding machining ' .. sName .. '-' .. sMilling + end + -- altrimenti non c'è il percorso + else + sMyWarn = 'warning in process ' .. tostring( Proc.Id) .. ' impossible make clean corner path' + end + -- altrimenti + else + sMyWarn = 'warning in process ' .. tostring( Proc.Id) .. ' impossible make clean corner path' + end + -- altrimenti diametro trovato è simile a quello già utilizzato +-- else +-- sMyWarn = 'warning in process ' .. tostring( Proc.Id) .. ' smaller tool not found' + end + -- altrimenti non è stata trovata lavorazione + else + sMyWarn = 'warning in process ' .. tostring( Proc.Id) .. ' clean corner milling/tool not found in library' + end + -- altrimenti non è stato trovato il punto comune +-- else +-- sMyWarn = 'warning in process ' .. tostring( Proc.Id) .. ' impossible make clean corner path' + end + -- altrimenti pareti sottosquadra o angolo aperto +-- else +-- sMyWarn = 'warning in process ' .. tostring( Proc.Id) .. ' impossible make clean corner path' + end + if #sMyWarn > 0 then + EgtOutLog( sMyWarn) + end + end + return true, sMyWarn +end --------------------------------------------------------------------- local function MakeCleanCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacInd, nAddGrpId, dDiam) @@ -911,7 +1095,7 @@ local function MakeCleanCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacInd, n local _, vtN1 = EgtSurfTmFacetCenter( Proc.Id, nFacInd, GDB_ID.ROOT) local _, vtN2 = EgtSurfTmFacetCenter( Proc.Id, tFacAdj[nIdLine][1], GDB_ID.ROOT) local _, vtN3 = EgtSurfTmFacetCenter( Proc.Id, tFacAdj[nIdLine][2], GDB_ID.ROOT) - + if not tFacAdj then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' geometry not found for clean corner' EgtOutLog( sErr) @@ -944,10 +1128,10 @@ local function MakeCleanCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacInd, n -- sommo i tre versori per avre una direzione media vtExtr = vtN1 + vtN2 + vtN3 vtExtr:normalize() - -- recupero la lavorazione - sMilling = ML.FindMilling( 'CleanCorner', (dDiam * 0.6)) + -- recupero la lavorazione non calcolando l'elevazione + sMilling = ML.FindMilling( 'CleanCorner', (dDiam*0.5)) if not sMilling then - local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' clean corner milling not found in library' + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' clean corner milling/tool not found in library' EgtOutLog( sErr) return false, sErr end @@ -956,6 +1140,13 @@ local function MakeCleanCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacInd, n local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) dMaxDepth = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxDepth end + -- l'altezza di taglio del tagliente corrisponde al raggio del raccordo che si riesce a coprire + -- quindi confronto l'elevazione con il raggio utensile utilizzato per la svuotatura + if dMaxDepth < (dDiam * 0.5) - 100 * GEO.EPS_SMALL then + sMyWarn = 'Warning on process ' .. tostring( Proc.Id) .. ' skip clean corner: the cut heigth is smaller to machine the corner radius' + EgtOutLog( sMyWarn) + return false, sMyWarn + end nAuxId = EgtLine( nAddGrpId, tFacAdj[nIdLine][nIdIniPoint], tFacAdj[nIdLine][nIdEndPoint], GDB_RT.GLOB) table.insert( pAuxId, nAuxId) -- se il punto finale corrisponde con il punto utilizzato in precedenza, uso l'altro @@ -1211,7 +1402,8 @@ local function MakeDrillOnCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacInd, end --------------------------------------------------------------------- -local function MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, dH, dV, dElev, bForceUseBlade) +local function MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, dH, dV, dElev, bForceUseBlade, dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, bOrthoFaces) + local sWarn -- Recupero le facce adiacenti alla principale local vAdj = EgtSurfTmFacetAdjacencies( Proc.Id, nFacInd)[1] if not vAdj or #vAdj == 0 then @@ -1317,14 +1509,6 @@ local function MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, end -- altrimenti con sega a catena else - -- Calcolo uso faccia - local nFaceUse = BL.GetNearestParalOpposite( rfFac:getVersZ()) - -- Calcolo angolo 3° asse rot (da direz. utensile) - local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nFacAdj, GDB_ID.ROOT) - local ptP1, ptP2 = EgtSurfTmFacetOppositeSide( Proc.Id, nFacAdj, rfFac:getVersZ(), GDB_ID.ROOT) - local vtT = vtN ^ (ptP2 - ptP1) - vtT:normalize() - local d3RotAng = EgtIf( abs( vtT:getZ()) < 0.1, 0, 90) -- Recupero la lavorazione local sSawing = ML.FindSawing( 'Sawing') if not sSawing then @@ -1349,52 +1533,135 @@ local function MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, EgtOutLog( sErr) return false, sErr end - -- Verifico se necessarie più passate - local nStep = ceil( ( dV - 10 * GEO.EPS_SMALL) / dSawThick) - local dStep = 0 - if nStep > 1 then - dStep = ( dV - dSawThick) / ( nStep - 1) + local bGoFromHead = true + -- verifico se la lunghezza utensile riesce ad arrivare sul fondo procedo nella modalità precedente + -- altrimenti se feature ha il flag come semitunnel allora provo a lavorarla come le fessure + if dElev > dMaxDepth + 10 * GEO.EPS_SMALL then + -- se ho il flag che indica che ha forma di semitunnel lavoro dal fianco + bGoFromHead = not bOrthoFaces end - for i = 1, nStep do - -- Applico la lavorazione con sega a catena a questa faccia - local sName = 'Csaw_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( i) - local nMchFId = EgtAddMachining( sName, sSawing) - if not nMchFId then - local sErr = 'Error adding machining ' .. sName .. '-' .. sSawing - EgtOutLog( sErr) - return false, sErr + -- se continuo a lavorare di testa + if bGoFromHead then + -- Calcolo uso faccia + local nFaceUse = BL.GetNearestParalOpposite( rfFac:getVersZ()) + -- Calcolo angolo 3° asse rot (da direz. utensile) + local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nFacAdj, GDB_ID.ROOT) + local ptP1, ptP2 = EgtSurfTmFacetOppositeSide( Proc.Id, nFacAdj, rfFac:getVersZ(), GDB_ID.ROOT) + local vtT = vtN ^ (ptP2 - ptP1) + vtT:normalize() + local d3RotAng = EgtIf( abs( vtT:getZ()) < 0.1, 0, 90) + -- Verifico se necessarie più passate + local nStep = ceil( ( dV - 10 * GEO.EPS_SMALL) / dSawThick) + local dStep = 0 + if nStep > 1 then + dStep = ( dV - dSawThick) / ( nStep - 1) end - -- aggiungo geometria - EgtSetMachiningGeometry( {{ Proc.Id, nFacAdj}}) - -- imposto uso faccia - EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) - -- imposto accorciamento iniziale/finale per estremi aperti/chiusi - EgtSetMachiningParam( MCH_MP.STARTADDLEN, EgtIf( bOpenStart, 0, - dSawWidth / 2)) - EgtSetMachiningParam( MCH_MP.ENDADDLEN, EgtIf( bOpenEnd, 0, - dSawWidth / 2)) - -- imposto angolo 3° asse rot - EgtSetMachiningParam( MCH_MP.BLOCKEDAXIS, 'A=' .. EgtNumToString( d3RotAng)) - -- imposto offset radiale - local dOffs = ( i - 1) * dStep - EgtSetMachiningParam( MCH_MP.OFFSR, dOffs) - -- se necessario, limito l'affondamento - if dElev > dMaxDepth + 10 * GEO.EPS_SMALL then - sWarn = 'Warning in LapJoint : elevation (' .. EgtNumToString( dElev, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth, 1) .. ')' - dDepth = dMaxDepth - dElev - EgtOutLog( sWarn .. ' (process ' .. tostring( Proc.Id) .. ')') - EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH '..EgtNumToString( dDepth, 1)) + for i = 1, nStep do + -- Applico la lavorazione con sega a catena a questa faccia + local sName = 'Csaw_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( i) + local nMchFId = EgtAddMachining( sName, sSawing) + if not nMchFId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sSawing + EgtOutLog( sErr) + return false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ Proc.Id, nFacAdj}}) + -- imposto uso faccia + EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) + -- imposto accorciamento iniziale/finale per estremi aperti/chiusi + EgtSetMachiningParam( MCH_MP.STARTADDLEN, EgtIf( bOpenStart, 0, - dSawWidth / 2)) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, EgtIf( bOpenEnd, 0, - dSawWidth / 2)) + -- imposto angolo 3° asse rot + EgtSetMachiningParam( MCH_MP.BLOCKEDAXIS, 'A=' .. EgtNumToString( d3RotAng)) + -- imposto offset radiale + local dOffs = ( i - 1) * dStep + EgtSetMachiningParam( MCH_MP.OFFSR, dOffs) + -- se necessario, limito l'affondamento + if dElev > dMaxDepth + 10 * GEO.EPS_SMALL then + sWarn = 'Warning in LapJoint : elevation (' .. EgtNumToString( dElev, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth, 1) .. ')' + dDepth = dMaxDepth - dElev + EgtOutLog( sWarn .. ' (process ' .. tostring( Proc.Id) .. ')') + EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH '..EgtNumToString( dDepth, 1)) + end + -- imposto elevazione + local sNotes = 'MaxElev=' .. EgtNumToString( dElev, 2) .. ';' + EgtSetMachiningParam( MCH_MP.USERNOTES, sNotes) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchFId, false) + return false, sErr + elseif EgtIsMachiningEmpty() then + _, sWarn = EgtGetMachMgrWarning( 0) + EgtSetOperationMode( nMchFId, false) + return false, sWarn + end end - -- imposto elevazione - local sNotes = 'MaxElev=' .. EgtNumToString( dElev, 2) .. ';' - EgtSetMachiningParam( MCH_MP.USERNOTES, sNotes) - -- eseguo - if not EgtApplyMachining( true, false) then - local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchFId, false) - return false, sErr - elseif EgtIsMachiningEmpty() then - local _, sWarn = EgtGetMachMgrWarning( 0) - EgtSetOperationMode( nMchFId, false) - return false, sWarn + -- altrimenti segacatena di fianco + else + -- verifico se posso farlo con la sega-catena + local bMakeChainSaw, sSawing2, dMaxMat2, dSawCornerRad2, dSawThick2 = VerifySawChain( Proc, dDimMin, dDimMax, vtOrtho) + if bMakeChainSaw then + -- Verifico se necessarie più passate + local nStep = ceil( ( dDimMin - 10 * GEO.EPS_SMALL) / dSawThick2) + local dStep = 0 + if nStep > 1 then + dStep = ( dDimMin - dSawThick2) / ( nStep - 1) + end + for i = 1, nStep do + -- inserisco la lavorazione di sawing + local sName = 'Csaw_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( i) + local nMchFId = EgtAddMachining( sName, sSawing2) + if not nMchFId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sSawing2 + EgtOutLog( sErr) + return false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ Proc.Id, nLundIdFace}}) + -- imposto uso del lato faccia + -- al momento, dato che la fessura è passante da parte a parte, gestisco solo la lavorazione + -- dall'alto e di fronte (da dietro è disabilitata perchè ho exracorsa con la FAST). + -- Questa feature non è applicata su facce di testa e quindi non controllo l'entrata in X + if abs(vtOrtho:getZ()) >= 0.707 then + EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_DOWN) + --elseif abs(vtOrtho:getZ()) < 0.707 and abs(vtOrtho:getY()) > 0.707 then + else + EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_BACK) + --elseif abs(vtOrtho:getZ()) <= 0.707 and vtOrtho:getY() < -0.707 then + -- EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_FRONT) + --elseif abs(vtOrtho:getZ()) < 0.707 and vtOrtho:getX() > 0.707 then + -- EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_LEFT) + --else + -- EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_RIGHT) + end + -- imposto offset radiale + local dOffs = ( i - 1) * dStep + EgtSetMachiningParam( MCH_MP.OFFSR, dOffs) + -- se possibile aumento l'affondamento pari al raggio corner + 1 + if dMaxMat2 > (dDepth + dSawCornerRad2 + 1) then + EgtSetMachiningParam( MCH_MP.DEPTH, (dDepth + dSawCornerRad2 + 1)) + -- se massimo affondamento supera altezza fessura, uso massimo affondamento + elseif dMaxMat2 > (dDepth + 1) then + EgtSetMachiningParam( MCH_MP.DEPTH, (dMaxMat2 - 1)) + -- se massimo affondamento utensile inferiore fessura, setto affondamento ed emetto warning + elseif dMaxMat2 < dDepth then + EgtSetMachiningParam( MCH_MP.DEPTH, dMaxMat2) + sWarn = 'Warning in process ' .. tostring( Proc.Id) .. ' : elevation bigger than max tool depth' + EgtOutLog( sWarn) + end + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchFId, false) + return false, sErr + elseif EgtIsMachiningEmpty() then + _, sWarn = EgtGetMachMgrWarning( 0) + EgtSetOperationMode( nMchFId, false) + return false, sWarn + end + end end end end @@ -1475,6 +1742,8 @@ local function MakePocket( Proc, nPartId, ptPs, tvtN, nFaceRef, sMchFind, nUseRo -- se ho lavorazione precedente ricalcolo grossolanamente l'elevazione if dPrevFaceElev and dPrevFaceElev > 0 and dAng then dElev = dElev + ( sqrt( ( dElev * dElev) - ( dPrevFaceElev * dPrevFaceElev)) * sin(dAng)) + elseif dPrevFaceElev and dPrevFaceElev > dElev then + dElev = dPrevFaceElev end local sPocketing if sMasterPocket then @@ -1777,6 +2046,215 @@ local function SetOpenSide( nPathInt, vtOrtho, b3Solid, nAddGrpId, bStartPoint) end end +--------------------------------------------------------------------- +local function ExtractExternalPaths( nPathInt, nNumIdAux, vtOrtho, b3Solid, nAddGrpId) + local nAuxId1, nAuxId2 + if nNumIdAux == 1 then + -- fondo tra loro le curve compatibili + EgtMergeCurvesInCurveCompo( nPathInt) + -- esplodo il percorso in modo da avere entià separate per poterle controllare + local nStartId, nNumIds = EgtExplodeCurveCompo( nPathInt) + if nStartId then + local sDeleteByDir + -- Se normale lungo la Z elimino le entità che hanno differenza in Z + if abs(vtOrtho:getZ()) > 0.7 then + sDeleteByDir = 'Z' + -- altrimenti se normale lungo la Y elimino le entità che hanno variazione in Y +-- elseif abs(vtOrtho:getZ()) < 0.001 and abs(vtOrtho:getY()) > 0.7 then + elseif abs(vtOrtho:getY()) > 0.7 then + sDeleteByDir = 'Y' + -- caso che non dovrebbe mai capitare ma gestito per completezza + -- altrimenti se normale lungo la X elimino le entità che hanno variazione in X +-- elseif abs(vtOrtho:getZ()) < 0.001 and abs(vtOrtho:getX()) > 0.7 then + elseif abs(vtOrtho:getX()) > 0.7 then + sDeleteByDir = 'X' + end + if sDeleteByDir then + for i = 1, nNumIds do + local ptP1 = EgtSP( ( nStartId + i - 1), GDB_RT.GLOB) + local ptP2 = EgtEP( ( nStartId + i - 1), GDB_RT.GLOB) + if sDeleteByDir == 'Z' then + -- se hanno variazione in Z cancello l'entità + if abs( ptP1:getZ() - ptP2:getZ()) > 10 * GEO.EPS_SMALL then + EgtErase( nStartId + i - 1) + end + elseif sDeleteByDir == 'Y' then + -- se hanno variazione in Y cancello l'entità + if abs( ptP1:getY() - ptP2:getY()) > 10 * GEO.EPS_SMALL then + EgtErase( nStartId + i - 1) + end + elseif sDeleteByDir == 'X' then + -- se hanno variazione in X cancello l'entità + if abs( ptP1:getX() - ptP2:getX()) > 10 * GEO.EPS_SMALL then + EgtErase( nStartId + i - 1) + end + end + end + -- ricreo i vari percorsi + local dLocalVal + local tPaths = {} + local nNumPaths + local dMaxVal + local dMinVal + for i = 1, nNumIds do + local ptP1 = EgtSP( ( nStartId + i - 1), GDB_RT.GLOB) + if ptP1 then + if sDeleteByDir == 'Z' then + local bInsTab + for j = 1, #tPaths do + local dLocalVal = tPaths[j][2] + if abs( ptP1:getZ() - dLocalVal) < 10 * GEO.EPS_SMALL then + local tLocIds = tPaths[j][1] + table.insert( tLocIds, ( nStartId + i - 1)) + tPaths[j][1] = tLocIds + bInsTab = true + end + end + -- se non ho trovato da inserirlo aggiungo nuovo elemento in tabella + if not bInsTab then + table.insert( tPaths, {{( nStartId + i - 1)}, ptP1:getZ()}) + dMaxVal = b3Solid:getMax():getZ() + dMinVal = b3Solid:getMin():getZ() + end + elseif sDeleteByDir == 'Y' then + local bInsTab + for j = 1, #tPaths do + local dLocalVal = tPaths[j][2] + if abs( ptP1:getY() - dLocalVal) < 10 * GEO.EPS_SMALL then + local tLocIds = tPaths[j][1] + table.insert( tLocIds, ( nStartId + i - 1)) + tPaths[j][1] = tLocIds + bInsTab = true + end + end + -- se non ho trovato da inserirlo aggiungo nuovo elemento in tabella + if not bInsTab then + table.insert( tPaths, {{( nStartId + i - 1)}, ptP1:getY()}) + dMaxVal = b3Solid:getMax():getY() + dMinVal = b3Solid:getMin():getY() + end + elseif sDeleteByDir == 'X' then + local bInsTab + for j = 1, #tPaths do + local dLocalVal = tPaths[j][2] + if abs( ptP1:getX() - dLocalVal) < 10 * GEO.EPS_SMALL then + local tLocIds = tPaths[j][1] + table.insert( tLocIds, ( nStartId + i - 1)) + tPaths[j][1] = tLocIds + bInsTab = true + end + end + -- se non ho trovato da inserirlo aggiungo nuovo elemento in tabella + if not bInsTab then + table.insert( tPaths, {{( nStartId + i - 1)}, ptP1:getX()}) + dMaxVal = b3Solid:getMax():getX() + dMinVal = b3Solid:getMin():getX() + end + end + end + end + + if tPaths then + local tChamPath = {} + -- elimino quelle che non corrispondono agli estremi + for i = 1, #tPaths do + -- se non corrisponde ai limiti elimino l'elemento + if abs( tPaths[i][2] - dMaxVal) > 10 * GEO.EPS_SMALL and abs( tPaths[i][2] - dMinVal) > 10 * GEO.EPS_SMALL then + tPaths[i] = nil + end + end + + for i = 1, #tPaths do + if tPaths[i] then + local tNoMatch = {} + local tPathLoc = tPaths[i][1] + local pIniLoc = EgtSP( tPathLoc[1], GDB_RT.GLOB) + local pEndLoc = EgtEP( tPathLoc[1], GDB_RT.GLOB) + -- ciclo sui percorsi per trovare i punti non coincidenti (se percorso non chiuso) + for j = 2, #tPathLoc do + -- prendo i punti del percorso successivo + local pAddIni = EgtSP( tPathLoc[j], GDB_RT.GLOB) + local pAddEnd = EgtEP( tPathLoc[j], GDB_RT.GLOB) + -- se consecutivi + if AreSamePointApprox( pEndLoc, pAddIni) then + pEndLoc = pAddEnd + elseif AreSamePointApprox( pIniLoc, pAddEnd) then + pIniLoc = pAddIni + else + table.insert( tNoMatch, tPathLoc[j]) + end + end + -- controllo eventuali percorsi scartati + for j = 1, #tNoMatch do + -- prendo i punti del percorso successivo + local pAddIni = EgtSP( tNoMatch[j], GDB_RT.GLOB) + local pAddEnd = EgtEP( tNoMatch[j], GDB_RT.GLOB) + -- se consecutivi + if AreSamePointApprox( pEndLoc, pAddIni) then + pEndLoc = pAddEnd + elseif AreSamePointApprox( pIniLoc, pAddEnd) then + pIniLoc = pAddIni + end + end + -- creo concatenamento partendo dal punto iniziale + local nIdLoc = EgtCurveCompoByReorder( nAddGrpId, tPathLoc, pIniLoc, true) + if nIdLoc then + table.insert( tChamPath, nIdLoc) + end + end + end + for i = 1, #tChamPath do + local ptP1 = EgtSP( tChamPath[i], GDB_RT.GLOB) + -- modifico estrusione percorso + if sDeleteByDir == 'Z' then + if abs(ptP1:getZ() - dMaxVal) < 10 * GEO.EPS_SMALL then + EgtModifyCurveExtrusion( tChamPath[i], Z_AX(), GDB_RT.GLOB) + else + EgtModifyCurveExtrusion( tChamPath[i], -Z_AX(), GDB_RT.GLOB) + end + elseif sDeleteByDir == 'Y' then + if abs(ptP1:getY() - dMaxVal) < 10 * GEO.EPS_SMALL then + EgtModifyCurveExtrusion( tChamPath[i], Y_AX(), GDB_RT.GLOB) + else + EgtModifyCurveExtrusion( tChamPath[i], -Y_AX(), GDB_RT.GLOB) + end + elseif sDeleteByDir == 'X' then + if abs(ptP1:getX() - dMaxVal) < 10 * GEO.EPS_SMALL then + EgtModifyCurveExtrusion( tChamPath[i], X_AX(), GDB_RT.GLOB) + else + EgtModifyCurveExtrusion( tChamPath[i], -X_AX(), GDB_RT.GLOB) + end + end + end + if #tChamPath == 1 then + return tChamPath[1], 1, nil + elseif #tChamPath == 2 then + return tChamPath[1], 2, tChamPath[2] + else + for i = 1, nNumIds do + EgtErase( nStartId + i - 1) + end + for i = 1, #tChamPath do + EgtErase( tChamPath[i]) + end + end + else + for i = 1, nNumIds do + EgtErase( nStartId + i - 1) + end + end + -- altrimenti cancello tutte le emtità e restituisco nil + else + for i = 1, nNumIds do + EgtErase( nStartId + i - 1) + end + end + end + end + + return nil, 0, nil +end + --------------------------------------------------------------------- local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCham, nAddGrpId, sMchFindMaster, b3FacesUsed, b3Solid, bOrthoFacesMaster) @@ -1802,8 +2280,8 @@ local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCha else bOrthoFaces = bOrthoFacesMaster end - - -- se è un tunnel provo a vedere se è possibile lavorarlo di con la svuotatura o con la sega catena + + -- se è un tunnel provo a vedere se è possibile lavorarlo con la svuotatura if bOrthoFaces then -- ottengo le dimensioni del tunnel dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, nSurfInt = GetTunnelDimension( Proc, nPartId) @@ -1818,79 +2296,95 @@ local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCha return -1, sErr end -- ottengo le curve di contorno libero - local nAuxId1, nNumIdAux + local nAuxId1, nAuxId2, nNumIdAux if b3FacesUsed then - nAuxId1, _ = EgtExtractSurfTmLoops( nSurfInt, nAddGrpId) - EgtModifyCurveExtrusion( nAuxId1, vtOrtho, GDB_RT.GLOB) - SetOpenSide( nAuxId1, vtOrtho, b3Solid, nAddGrpId, true) - nNumIdAux = 2 +-- nAuxId1, _ = EgtExtractSurfTmLoops( nSurfInt, nAddGrpId) +-- EgtModifyCurveExtrusion( nAuxId1, vtOrtho, GDB_RT.GLOB) +-- SetOpenSide( nAuxId1, vtOrtho, b3Solid, nAddGrpId, true) +-- nNumIdAux = 2 + + -- estraggo i percorsi + nAuxId1, nNumIdAux = EgtExtractSurfTmLoops( Proc.Id, nAddGrpId) + -- se percorso creato estraggo solo i percorsi delle facce interessate, non di testa + if nAuxId1 then + nAuxId1, nNumIdAux, nAuxId2 = ExtractExternalPaths( nAuxId1, nNumIdAux, vtOrtho, b3Solid, nAddGrpId) + end else nAuxId1, nNumIdAux = EgtExtractSurfTmLoops( Proc.Id, nAddGrpId) + if not nNumIdAux then nNumIdAux = 0 end end - if nAuxId1 then - local dExtra = 2 - for i = 1, nNumIdAux do - local AuxId - if b3FacesUsed then - if i == 1 then - AuxId = nAuxId1 - else - -- faccio la copia del percorso - AuxId = EgtCopyGlob( nAuxId1, nAddGrpId) - end + local dExtra = 2 + for i = 1, nNumIdAux do + local AuxId + local vtExtr + if b3FacesUsed then + if i == 1 then + AuxId = nAuxId1 else - AuxId = nAuxId1 + i - 1 + -- faccio la copia del percorso +-- AuxId = EgtCopyGlob( nAuxId1, nAddGrpId) + AuxId = nAuxId2 end - local vtExtr, _, _ = EgtCurveArea( AuxId) - local fFrCurve = EgtGetGlobFrame( AuxId) - if vtExtr then + if AuxId then + vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) + end + else + AuxId = nAuxId1 + i - 1 + vtExtr, _, _ = EgtCurveArea( AuxId) + end + if vtExtr then + if not b3FacesUsed then + local fFrCurve = EgtGetGlobFrame( AuxId) vtExtr:toGlob( fFrCurve) - if b3FacesUsed and i == nNumIdAux then - vtExtr = -vtExtr + end +-- if b3FacesUsed and i == nNumIdAux then +-- vtExtr = -vtExtr +-- end + -- Se normale entro certi limiti +-- if vtExtr:getZ() > -0.707 and ( abs(vtOrtho:getX()) > 0.99 or abs(vtOrtho:getY()) > 0.99 or abs(vtOrtho:getZ()) > 0.99) then + if vtExtr:getZ() > -0.707 and ( abs(vtExtr:getX()) > 0.99 or abs(vtExtr:getY()) > 0.99 or abs(vtExtr:getZ()) > 0.99) then + -- inserisco la lavorazione + local sNameCh = 'Cham_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( i) + local nMchId = EgtAddMachining( sNameCh, sMilling) + if not nMchId then + local sErr = 'Error adding machining ' .. sNameCh .. '-' .. sMilling + EgtOutLog( sErr) + return -1, sErr end - if vtExtr:getZ() > -0.707 and ( abs(vtOrtho:getX()) > 0.99 or abs(vtOrtho:getY()) > 0.99 or abs(vtOrtho:getZ()) > 0.99) then - -- inserisco la lavorazione - local sNameCh = 'Cham_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( i) - local nMchId = EgtAddMachining( sNameCh, sMilling) - if not nMchId then - local sErr = 'Error adding machining ' .. sNameCh .. '-' .. sMilling - EgtOutLog( sErr) - return -1, sErr - end - -- modifico estrusione percorso - EgtModifyCurveExtrusion( AuxId, vtExtr, GDB_RT.GLOB) - -- aggiungo geometria - EgtSetMachiningGeometry( {{ AuxId, -1}}) - -- imposto posizione braccio porta testa - if vtExtr:getY() < GEO.EPS_SMALL then - EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM) - else - EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP) - end - EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) - -- assegno affondamento e offset radiale - EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra - EgtIf( b3FacesUsed, (dDepth / 2), 0)) - EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) - -- se opero su 3 facce e sono al secondo e ultimo percorso inverto la lavorazione - if b3FacesUsed and i == nNumIdAux then - EgtSetMachiningParam( MCH_MP.INVERT, true) - end - -- eseguo - if not EgtApplyMachining( true, false) then - local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchId, false) - return -1, sErr - end - -- se non perpendicolare emetto un warning - -- else - -- sWarn = 'Warning in process ' .. tostring( Proc.Id) .. ' : chamfer skipped because not perpendicular to face or from bottom' - -- EgtOutLog( sWarn) + -- modifico estrusione percorso + EgtModifyCurveExtrusion( AuxId, vtExtr, GDB_RT.GLOB) + -- aggiungo geometria + EgtSetMachiningGeometry( {{ AuxId, -1}}) + -- imposto posizione braccio porta testa + if vtExtr:getY() < GEO.EPS_SMALL then + EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM) + else + EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP) end - --emetto un warning + EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) + -- assegno affondamento e offset radiale +-- EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra - EgtIf( b3FacesUsed, (dDepth / 2), 0)) + EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra) + EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) + -- se opero su 3 facce e sono al secondo e ultimo percorso inverto la lavorazione +-- if b3FacesUsed and i == nNumIdAux then +-- EgtSetMachiningParam( MCH_MP.INVERT, true) +-- end + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchId, false) + return -1, sErr + end + -- se non perpendicolare emetto un warning -- else - -- sWarn = 'Warning in process ' .. tostring( Proc.Id) .. ' : chamfer skipped because not perpendicular to face' + -- sWarn = 'Warning in process ' .. tostring( Proc.Id) .. ' : chamfer skipped because not perpendicular to face or from bottom' -- EgtOutLog( sWarn) end + --emetto un warning + -- else + -- sWarn = 'Warning in process ' .. tostring( Proc.Id) .. ' : chamfer skipped because not perpendicular to face' + -- EgtOutLog( sWarn) end end end @@ -2048,11 +2542,11 @@ local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCha end end - return 0, sWarn, dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace + return 0, sWarn, dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, bOrthoFaces end --------------------------------------------------------------------- -local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId) +local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, bSingle_part) local sWarn -- recupero l'ingombro del grezzo di appartenenza local b3Raw = EgtGetRawPartBBox( nRawId) @@ -2064,8 +2558,10 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId) return false, sErr end local bClosedOrthoFaces + local nFacInd, dFacElev, nFacInd2, dFacElev2 -- recupero la faccia con il maggior numero di adiacenze e l'elevazione relativa - local nFacInd, dFacElev, nFacInd2, dFacElev2 = BL.GetFaceWithMostAdj( Proc.Id, nPartId) + nFacInd, dFacElev, nFacInd2, dFacElev2 = BL.GetFaceWithMostAdj( Proc.Id, nPartId) + if not nFacInd or nFacInd < 0 then if nFacInd == -1 then bClosedOrthoFaces = nFacInd2 @@ -2208,33 +2704,33 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId) end -- altrimenti lavoro con svuotatura else - -- se smusso non è esclusivo - if nChamfer < 2 then - local bSpecial3faces = false - -- verifico se sono nel caso in cui la faccia esclusa ha elevazione più alta - -- in ogni caso a parità di adiacenze la funzione BL.GetFaceWithMostAdj restituisce le facce con minore elevazione --- if not bIsU and bIsL and Proc.Fct <= 3 and nFacInd ~= 0 and nFacInd2 ~= 0 then - if not bIsU and bIsL and Proc.Fct <= 3 then - -- verifico se l'elevazione della faccia esclusa è maggiore dell'elevazione delle altre due facce - local nFaceMaxElev = 0 - if Proc.Fct == 3 then - for i = 1, Proc.Fct do - if (i-1) ~= nFacInd and (i-1) ~= nFacInd2 then - nFaceMaxElev = (i-1) - end + local bSpecial3faces = false + -- verifico se sono nel caso in cui la faccia esclusa ha elevazione più alta + if not bIsU and bIsL and Proc.Fct <= 3 and nFacInd ~= 0 and nFacInd2 ~= 0 then +-- if not bIsU and bIsL and Proc.Fct <= 3 then + -- verifico se l'elevazione della faccia esclusa è maggiore dell'elevazione delle altre due facce + local nFaceMaxElev = 0 + if Proc.Fct == 3 then + for i = 1, Proc.Fct do + if (i-1) ~= nFacInd and (i-1) ~= nFacInd2 then + nFaceMaxElev = (i-1) end end - local rfFac0 = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFaceMaxElev, GDB_ID.ROOT) - -- ottengo il box con la normale della faccia 0 - local bBoxF0 = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, rfFac0) - local dElevF0 = bBoxF0:getDimZ() - -- se effettivamente l'elevazione della faccia esclusa è maggiore delle altre elevazioni segno il flag per le 3 facce speciali - if dElevF0 > dFacElev and dElevF0 > dFacElev2 then - bSpecial3faces = true - end end - -- se lavorazioni di svuotatura e contornatura - if bSpecial3faces then + local rfFac0 = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFaceMaxElev, GDB_ID.ROOT) + -- ottengo il box con la normale della faccia 0 + local bBoxF0 = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, rfFac0) + local dElevF0 = bBoxF0:getDimZ() + -- se effettivamente l'elevazione della faccia esclusa è maggiore delle altre elevazioni segno il flag per le 3 facce speciali + if dElevF0 > dFacElev and dElevF0 > dFacElev2 then + bSpecial3faces = true + end + end + -- se riconosciuta gestione 3 facce + -- e limitata per ora alla feature 20 + if bSpecial3faces and Proc.Prc == 20 then + -- se smusso non è esclusivo + if nChamfer < 2 then -- entrambe le facce non devono essere orientate verso il basso local _, vtN2 = EgtSurfTmFacetCenter( Proc.Id, nFacInd2, GDB_ID.ROOT) -- se orientata verso il basso, verifico l'alternativa @@ -2247,7 +2743,7 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId) rfFac2, dH2, dV2 = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFacInd2, GDB_ID.ROOT) -- eventuali tagli preliminari do - local bOk, sErr = MakePreCuts( Proc, nPhase, nRawId, nPartId, b3Raw) + local bOk, sErr = MakePreCuts( Proc, nPhase, nRawId, nPartId, b3Raw, nChamfer) if not bOk then return false, sErr end end -- Recupero la lavorazione di fresa @@ -2258,7 +2754,11 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId) return false, sErr end -- Recupero la lavorazione di svuotatura - local sMchFind = 'OpenPocket' + local sMchFind = 'Pocket' + -- se forzato uso truciolatore + if EgtGetInfo( Proc.Id, sUseRoughTool, 'i') == 1 then + sMchFind = 'OpenPocket' + end local dDiam = min( dH, dV) local dDiam2 = min( dH2, dV2) local dCollSic = 2 * BD.COLL_SIC @@ -2335,94 +2835,116 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId) bOk, sWarn = MakeDrillOnCorner( Proc, nPhase, nRawId, nPartId, b3Raw, 0, nAddGrpId, dDiamTool, true) if not bOk then return false, sWarn end end - -- altrimenti lavorazione di svuotatura o contornatura - else - -- se orientata verso il basso, verifico l'alternativa - if vtN:getZ() < BD.NZ_MINA and nFacInd2 then - ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nFacInd2, GDB_ID.ROOT) - nFacInd, nFacInd2 = nFacInd2, nFacInd - dFacElev, dFacElev2 = dFacElev2, dFacElev - end - rfFac, dH, dV = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFacInd, GDB_ID.ROOT) - -- verifico non sia orientata verso il basso - local bFaceOk = ( vtN:getZ() >= BD.NZ_MINA) - if not bFaceOk then - local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' LapJoint from bottom impossible' - EgtOutLog( sErr) - return false, sErr - end - -- eventuali tagli preliminari - do - local bOk, sErr = MakePreCuts( Proc, nPhase, nRawId, nPartId, b3Raw) - if not bOk then return false, sErr end - end - -- recupero la lavorazione - local nUseRoughTool = 0 - local sMchFind = 'Pocket' - if Proc.Fct < 3 or bIsU or bIsL then - sMchFind = 'OpenPocket' - -- abilito il truciolatore + end + -- altrimenti lavorazione di svuotatura o contornatura + else + -- se orientata verso il basso, verifico l'alternativa + if vtN:getZ() < BD.NZ_MINA and nFacInd2 then + ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nFacInd2, GDB_ID.ROOT) + nFacInd, nFacInd2 = nFacInd2, nFacInd + dFacElev, dFacElev2 = dFacElev2, dFacElev + end + rfFac, dH, dV = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFacInd, GDB_ID.ROOT) + -- verifico non sia orientata verso il basso + local bFaceOk = ( vtN:getZ() >= BD.NZ_MINA) + if not bFaceOk then + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' LapJoint from bottom impossible' + EgtOutLog( sErr) + return false, sErr + end + -- eventuali tagli preliminari + do + local bOk, sErr = MakePreCuts( Proc, nPhase, nRawId, nPartId, b3Raw, nChamfer) + if not bOk then return false, sErr end + end + -- recupero la lavorazione + local nUseRoughTool = 0 + local sMchFind = 'Pocket' + -- se processo 20 vedo se ho truciolatore abilitato + if Proc.Prc == 20 then + -- se forzato uso truciolatore altrimenti prosegue con fresa più piccola + if EgtGetInfo( Proc.Id, sUseRoughTool, 'i') == 1 then + sMchFind = 'OpenPocket' nUseRoughTool = 1 end - local dDiam = min( dH, dV) - local dCollSic = 2 * BD.COLL_SIC - if abs( vtN:getX()) > 0.996 or abs( vtN:getY()) > 0.996 or abs( vtN:getZ()) > 0.996 then dCollSic = 0 end - --EgtOutLog( 'Mortise Find Diam =' .. EgtNumToString( dDiam)) - local sPocketing = ML.FindPocketing( sMchFind, dDiam, dFacElev + dCollSic) - -- se non trova una svuotatura adatta - if not sPocketing then - -- provo con contornatura - if bIsL then + else + -- Se feature lavorata in singolo passo uso fresa (richiesta di Alessandro) + if bSingle_part and not bIsL and not bIsU then + -- disabilito il truciolatore + sMchFind = 'Pocket' + nUseRoughTool = 0 + -- altrimenti va lavorata in passo multiplo + else + -- abilito il truciolatore + sMchFind = 'OpenPocket' + nUseRoughTool = 1 + end + end + local dDiam = min( dH, dV) + local dCollSic = 2 * BD.COLL_SIC + if abs( vtN:getX()) > 0.996 or abs( vtN:getY()) > 0.996 or abs( vtN:getZ()) > 0.996 then dCollSic = 0 end + --EgtOutLog( 'Mortise Find Diam =' .. EgtNumToString( dDiam)) + local sPocketing = ML.FindPocketing( sMchFind, dDiam, dFacElev + dCollSic) + -- se non trova una svuotatura adatta + if not sPocketing then + -- se forma a L provo con contornatura + if bIsL then + -- se smusso non è esclusivo + if nChamfer < 2 then return MakeByMill( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, dH, dV, dFacElev) - -- altrimenti provo con la sega a catena o lama - else - local bTryWithBlades = true - local nOk, bOk, sErr, sStat - -- in base al flag interno e al numero di facce e se ha forma ad U: provo prima la svuotatura sul fianco e - -- se non è possibile allora provo in seguito con lama o segacatena - -- o passare subito dalla lavorazione con lama/sega catena - if bTrySidePocketAtFirst and Proc.Fct == 3 and bIsU then - nOk, sWarn = MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCham, nAddGrpId, 'OpenPocket', true, b3Solid) - if nOk < 0 then - return false, sWarn - elseif nOk > 0 then - bTryWithBlades = false - end - bOk = true + end + -- altrimenti provo con la sega a catena o lama + else + local bTryWithBlades = true + local nOk, bOk, sStat, sErr, dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, bOrthoFaces + -- in base al flag interno e al numero di facce e se ha forma ad U: provo prima la svuotatura sul fianco e + -- se non è possibile allora provo in seguito con lama o segacatena + -- o passare subito dalla lavorazione con lama/sega catena + if bTrySidePocketAtFirst and Proc.Fct == 3 and bIsU then + -- lavoro con svuotature (singola o doppia contrapposta) + nOk, sErr, dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, bOrthoFaces = MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCham, nAddGrpId, sMchFind, true, b3Solid) + if nOk < 0 then + return false, sErr + elseif nOk > 0 then + bTryWithBlades = false end - -- Se la svuotatura precedente non è stata fatta provo con le lame - if bTryWithBlades then - bOk, sWarn, sStat = MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, dH, dV, dFacElev, bForceUseBlade) - if not bOk and sStat == 'MNF' then - sPocketing = ML.FindPocketing( sMchFind, dDiam) - if not sPocketing then - local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' pocketing not found in library' - EgtOutLog( sErr) - return false, sErr - end - else - return bOk, sWarn + bOk = true + end + -- Se la svuotatura precedente non è stata fatta e smusso non è esclusivo, provo con le lame + if bTryWithBlades and nChamfer < 2 then + bOk, sWarn, sStat = MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, dH, dV, dFacElev, bForceUseBlade, dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, bOrthoFaces) + if not bOk and sStat == 'MNF' then + sPocketing = ML.FindPocketing( sMchFind, dDiam) + if not sPocketing then + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' pocketing not found in library' + EgtOutLog( sErr) + return false, sErr end - -- altrimenti ho già svuotato dal fianco, esco else return bOk, sWarn end + -- altrimenti ho già svuotato dal fianco, esco + else + return bOk, sWarn end end - -- se richiesti antischeggia con lama su U trasversale - -- rimane da gestire: se da eseguire con fresa o se richiesto lama ma impossibile utilizzarla, si utilizza fresa - local bMadeASbyBld = false - if EgtGetInfo( Proc.Id, sAntisplintMode, 'i') == 1 and bIsU and - ( Proc.Box:getDimY() > b3Raw:getDimY() - 1 or Proc.Box:getDimZ() > b3Raw:getDimZ() - 1) then - -- va eseguito sulle facce diverse dalla principale - for nFacet = 0, 2 do - if nFacet ~= nFacInd then - bMadeASbyBld, sWarn = MakeAntiSplintBySaw( Proc, nFacet, vtN, b3Raw) - if not bMadeASbyBld then return false, sWarn end - end + end + -- se richiesti antischeggia con lama su U trasversale e smusso non esclusivo + -- rimane da gestire: se da eseguire con fresa o se richiesto lama ma impossibile utilizzarla, si utilizza fresa + local bMadeASbyBld = false + if nChamfer < 2 and EgtGetInfo( Proc.Id, sAntisplintMode, 'i') == 1 and bIsU and + ( Proc.Box:getDimY() > b3Raw:getDimY() - 1 or Proc.Box:getDimZ() > b3Raw:getDimZ() - 1) then + -- va eseguito sulle facce diverse dalla principale + for nFacet = 0, 2 do + if nFacet ~= nFacInd then + bMadeASbyBld, sWarn = MakeAntiSplintBySaw( Proc, nFacet, vtN, b3Raw) + if not bMadeASbyBld then return false, sWarn end end end + end + -- se smusso non esclusivo + if nChamfer < 2 then -- eseguo la svuotatura della faccia principale, mi restituisce id utensile, il diametro utensile per il foro opzionale local tvtNx = {} tvtNx[2] = vtN @@ -2468,10 +2990,16 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId) local bOk bOk, sWarn = MakeDrillOnCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacInd, nAddGrpId, dDiamTool) if not bOk then return false, sWarn end + -- altrimenti se abilitato dal parametro Q inserisco percorso di pulitura elseif EgtGetInfo( Proc.Id, sInsertBoreOnCorner, 'i') == 2 then local bOk bOk, sWarn = MakeCleanCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacInd, nAddGrpId, dDiamTool) if not bOk then return false, sWarn end + -- altrimenti se abilitato dal parametro Q inserisco contorno con fresa più piccola + elseif EgtGetInfo( Proc.Id, sMakeContourWithSmallTool, 'i') == 1 then + local bOk + bOk, sWarn = MakeContourCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacInd, nAddGrpId, dDiamTool) + if not bOk then return false, sWarn end end end end @@ -2517,7 +3045,7 @@ local function MakeLongMoreFaces( Proc, nPhase, nRawId, nPartId) local b3Box = EgtGetBBoxGlob( vAddId[i], GDB_BB.STANDARD) local nFct = EgtSurfTmFacetCount( vAddId[i]) local AddProc = { Id = vAddId[i], Grp = Proc.Grp, Prc = Proc.Prc, Box = b3Box, Fct = nFct, Flg = Proc.Flg} - local bOk, sMyWarn = MakeMoreFaces( AddProc, nPhase, nRawId, nPartId) + local bOk, sMyWarn = MakeMoreFaces( AddProc, nPhase, nRawId, nPartId, false) if not bOk then return bOk, sWarn end if not sWarn then sWarn = sMyWarn end end @@ -2587,7 +3115,7 @@ function ProcessLapJoint.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) end -- tre o più facce else - return MakeMoreFaces( Proc, nPhase, nRawId, nPartId) + return MakeMoreFaces( Proc, nPhase, nRawId, nPartId, true) end end end