From c40fa8ff10ab7f083f5d15a8ae9295ba90f71e7b Mon Sep 17 00:00:00 2001 From: SaraP Date: Wed, 13 Jul 2022 10:54:29 +0200 Subject: [PATCH] 3dPrinting : - correzioni nelle intersezioni costolature. --- LuaLibs/AddManData.lua | 1 + LuaLibs/CalcPaths.lua | 45 ++++++++++++++++++----- LuaLibs/CalcToolPath.lua | 77 +++++++++++++++++++++++++++++++--------- 3 files changed, 99 insertions(+), 24 deletions(-) diff --git a/LuaLibs/AddManData.lua b/LuaLibs/AddManData.lua index d105312..9303e72 100644 --- a/LuaLibs/AddManData.lua +++ b/LuaLibs/AddManData.lua @@ -81,6 +81,7 @@ KEY_RIBS_LEAD_OUT_COASTING = "RibsLeadOutCoasting" KEY_RIBS_LEAD_OUT_WIPE = "RibsLeadOutWipe" KEY_RIBS_LEAD_OUT_WIPE_DIR = "RibsLeadOutWipeDir" KEY_RIBS_INTERS = "RibsHaveIntersections" +KEY_SPLIT_RIB = "SplitRib" -- Parametri di macchina SEC_3DPRINTING = "3dPrinting" diff --git a/LuaLibs/CalcPaths.lua b/LuaLibs/CalcPaths.lua index 2669e72..46b0990 100644 --- a/LuaLibs/CalcPaths.lua +++ b/LuaLibs/CalcPaths.lua @@ -116,8 +116,9 @@ local function TrimRibsOffset( nCrv, nOffs1, nOffs2, nOffsGrp, bIn) dPar1, dPar2 = dPar2, dPar1 end local nCopy = EgtCopyGlob( nCrv, nOffsGrp) - EgtTrimCurveEndAtParam( EgtIf( bIn, nCrv, nCopy), dPar1) - EgtTrimCurveStartAtParam( EgtIf( bIn, nCopy, nCrv), dPar2) + EgtTrimCurveEndAtParam( nCrv, dPar1) + EgtTrimCurveStartAtParam( nCopy, dPar2) + EgtSetInfo( nCopy, KEY_SPLIT_RIB, nCrv) elseif dPar1 or dPar2 then if bIn then @@ -291,13 +292,20 @@ end -------------------------------------------------------------------- -- Funzione che riordina le costolature nel caso generico -local function ReorderRibs( nGrp, bInvertOrder) +local function ReorderRibs( nGrp, bInvertOrder, nShells) EgtSpInit() local vIds = EgtGetNameInGroup( nGrp, RIBS_CRV .. '*') + local vSplitRibs = {} for i = 1, #vIds do - local pt = EgtMP( vIds[i], GDB_RT.GLOB) - EgtSpAddPoint( pt:getX(), pt:getY(), pt:getZ(), 0, 0, pt:getX(), pt:getY(), pt:getZ(), 0, 0) + local nInfo = EgtGetInfo( vIds[i], KEY_SPLIT_RIB, 'i') + -- se è ottenuto dalla divisione di una costolatura non va considerato per il TSP ( viene aggiunto in seguito) + if nInfo and nShells == 1 then + table.insert( vSplitRibs, vIds[i]) + else + local pt = EgtMP( vIds[i], GDB_RT.GLOB) + EgtSpAddPoint( pt:getX(), pt:getY(), pt:getZ(), 0, 0, pt:getX(), pt:getY(), pt:getZ(), 0, 0) + end end local vOrd, dLen = EgtSpCalculate( SHP_TY.OPEN) EgtSpTerminate() @@ -306,6 +314,14 @@ local function ReorderRibs( nGrp, bInvertOrder) for i = 2, #vOrd do EgtRelocateGlob( vIds[vOrd[i]], vIds[vOrd[i-1]], EgtIf( bInvertOrder, GDB_IN.BEFORE, GDB_IN.AFTER)) end + + -- aggiusto tutte le costolature divise + for i = 1, #vSplitRibs do + local nPrevId = EgtGetInfo( vSplitRibs[i], KEY_SPLIT_RIB, 'i') + -- aggiungo come successiva alla costolatura da cui si è generata + EgtRelocateGlob( vSplitRibs[i], nPrevId, GDB_IN.AFTER) + end + end --------------------------------------------------------------------------------------------- @@ -404,18 +420,31 @@ local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nStmId) -- gestione caso speciale di intersezione e 2 passate ReorderRibsInters2Shells( nRibsPathGrp, LayerParams.dStrand) else - ReorderRibs( nRibsPathGrp, LayerParams.bRibsInvertOrder) + ReorderRibs( nRibsPathGrp, LayerParams.bRibsInvertOrder, LayerParams.nRibsShellsNbr) end -- eseguo il trim delle costole con la regione offsettata + local vErased = {} local vOrderedRibs = EgtGetNameInGroup( nRibsPathGrp, RIBS_CRV .. '*') for i = 1, #vOrderedRibs do - local nCrv, nCnt = EgtTrimCurveWithRegion( vOrderedRibs[i], nSrf, true, false) + local nCrv, nCnt = EgtTrimCurveWithRegion( vOrderedRibs[i], nSrf, true, false) + if nCnt == 0 then + -- lo aggiungo nella tabella delle costolature eliminate + vErased[vOrderedRibs[i]] = 1 + end -- elimino tratti troppo corti for nId = nCrv, nCrv + nCnt - 1 do - local dLen = EgtCurveLength( nId) + local dLen = EgtCurveLength( nId) if dLen < 10 * MIN_LEN then EgtErase( nId) + -- lo aggiungo nella tabella delle costolature eliminate + vErased[vOrderedRibs[i]] = 1 + else + local nInfo = EgtGetInfo( nId, KEY_SPLIT_RIB, 'i') + -- se la costolatura da cui deriva è stata eliminata, tolgo l'info che le associava + if nInfo and vErased[nInfo] then + EgtRemoveInfo( nId, KEY_SPLIT_RIB) + end end end end diff --git a/LuaLibs/CalcToolPath.lua b/LuaLibs/CalcToolPath.lua index 47cfe70..92a0520 100644 --- a/LuaLibs/CalcToolPath.lua +++ b/LuaLibs/CalcToolPath.lua @@ -178,8 +178,27 @@ local function AddRetractionOnLastCrv( nTpathGrpId, LayerParams) end -------------------------------------------------------------------- -local function CalcRibsLink( ptS, ptE, nCurr, nLoopGrp, bForceLink) +local function VerifyRibsLink( nLinkId, nCurr, nNext) + -- verifico se il link interseca una delle altre costolature + local nGrp = EgtGetParent( nCurr) + local vRibsIds = EgtGetNameInGroup( nGrp, RIBS_CRV .. '*') + for i = 1, #vRibsIds do + if vRibsIds[i] ~= nCurr and vRibsIds[i] ~= nNext then + local ptInt = EgtIP( nLinkId, vRibsIds[i], ORIG()) + if ptInt then return false end + end + end + + return true +end + +-------------------------------------------------------------------- +local function CalcRibsLink( nCurr, nNext, nLoopGrp, bForceLink) + + local ptS = EgtEP( nCurr) + local ptE = EgtSP( nNext) + local nCrvId = EgtGetFirstInGroup( nLoopGrp) -- recupero la curva di offset su cui calcolare link while nCrvId do @@ -217,6 +236,13 @@ local function CalcRibsLink( ptS, ptE, nCurr, nLoopGrp, bForceLink) EgtTrimCurveStartEndAtParam( nLinkId, dParS, dParE) EgtSetInfo( nLinkId, KEY_TYPE, TYPE.RIB) if bInvert then EgtInvertCurve( nLinkId) end + -- verifico se è valido + local bValid = VerifyRibsLink( nLinkId, nCurr, nNext) + if not bValid then + EgtErase( nLinkId) + EgtErase( nCopyId) + return + end if bClosed then EgtTrimCurveStartEndAtParam( nCrvId, dParE, dParS) @@ -225,8 +251,8 @@ local function CalcRibsLink( ptS, ptE, nCurr, nLoopGrp, bForceLink) EgtTrimCurveEndAtParam( nCrvId, dParS) EgtTrimCurveStartAtParam( nCopyId, dParE) end - - return nLinkId + + return nLinkId end nCrvId = EgtGetNext( nCrvId) @@ -446,38 +472,59 @@ local function CalcRibsToolPath( nCrvGrp, nTpathGrpId, LayerParams, dCorrZ) local bInters = EgtGetInfo( nRibsGrp, KEY_RIBS_INTERS, 'b') or false local bSpecialCase = bInters and LayerParams.nRibsShellsNbr == 2 + local bSwap = false -- orientamento delle curve - local bInvert = LayerParams.bRibsInvert + local bInvert = LayerParams.bRibsInvert if not bSpecialCase then for i = 1, #tabRibs do + local nInfo = EgtGetInfo( tabRibs[i][1], KEY_SPLIT_RIB, 'i') + -- aggiorno bInvert per il gruppo di costolature analizzato + if i > 1 and not nInfo then + if LayerParams.bRibsLink and LayerParams.nRibsShellsNbr % 2 == 1 then + bInvert = not bInvert + end + end + + if LayerParams.nRibsShellsNbr == 1 and nInfo and bInvert then + -- se inverto direzione di costolature divise allora devo invertirne anche l'ordine di realizzazione + bSwap = true + EgtRelocateGlob( tabRibs[i][1], tabRibs[i-1][1], GDB_IN.BEFORE) + end + -- oriento tutte le passate relative ad una stessa costolatura for j = 1, #tabRibs[i] do if ( bInvert and j % 2 == 1) or ( not bInvert and j % 2 == 0) then EgtInvertCurve( tabRibs[i][j]) end end - -- aggiorno bInvert per il gruppo di costolature successivo - if LayerParams.bRibsLink and LayerParams.nRibsShellsNbr % 2 == 1 then - bInvert = not bInvert - end end end -- Link + -- se modifiche nell'ordine ricalcolo i gruppi di costolature + if bSwap then + tabRibs = {} + nFirst = EgtGetFirstNameInGroup( nTpathGrpId, RIBS_CRV .. '*') + while nFirst do + local sName = EgtGetName( nFirst) + local vIds = EgtGetNameInGroup( nTpathGrpId, sName) + table.insert( tabRibs, vIds) + nFirst = EgtGetNextName( vIds[#vIds], RIBS_CRV .. '*') + end + end + -- collego le passate di una stessa costolatura for i = 1, #tabRibs do for j = 1, #tabRibs[i] - 1 do - local ptS = EgtEP( tabRibs[i][j]) - local ptE = EgtSP( tabRibs[i][j + 1]) - CalcRibsLink( ptS, ptE, tabRibs[i][j], nLoopGrp, true) + CalcRibsLink( tabRibs[i][j], tabRibs[i][j + 1], nLoopGrp, true) if not bSpecialCase then -- creo link fittizio per eliminare tratto corrispondente sulla curva di offset - local nFakeLink = CalcRibsLink( EgtSP( tabRibs[i][j]), EgtEP( tabRibs[i][j + 1]), tabRibs[i][j], nLoopGrp, false) + local nFakeLink = CalcRibsLink( tabRibs[i][j + 1], tabRibs[i][j], nLoopGrp, false) EgtErase( nFakeLink) end end if bSpecialCase then - local nFakeLink = CalcRibsLink( EgtSP( tabRibs[i][1]), EgtEP( tabRibs[i][#tabRibs[i]]), tabRibs[i][1], nLoopGrp, false) + local nFakeLink = CalcRibsLink( tabRibs[i][#tabRibs[i]], tabRibs[i][1], nLoopGrp, false) EgtErase( nFakeLink) end end @@ -485,9 +532,7 @@ local function CalcRibsToolPath( nCrvGrp, nTpathGrpId, LayerParams, dCorrZ) if LayerParams.bRibsLink then for i = 1, #tabRibs - 1 do local nCnt = #tabRibs[i] - local ptS = EgtEP( tabRibs[i][nCnt]) - local ptE = EgtSP( tabRibs[i + 1][1]) - CalcRibsLink( ptS, ptE, tabRibs[i][nCnt], nLoopGrp, false) + CalcRibsLink( tabRibs[i][nCnt], tabRibs[i + 1][1], nLoopGrp, false) end end