From 4a211ef9c397ba18969f0d7b8f5fd8d229348ef1 Mon Sep 17 00:00:00 2001 From: SaraP Date: Fri, 26 Aug 2022 10:38:51 +0200 Subject: [PATCH] 3dPrinting : - aggiunti parametri coasting e wipe nelle regioni con diverso numero di passate. --- LuaLibs/AddManData.lua | 4 ++++ LuaLibs/CalcPaths.lua | 25 +++++++++++++------ LuaLibs/CalcToolPath.lua | 52 +++++++++++++++++++++++++++------------- LuaLibs/RunSlicing.lua | 4 ++++ 4 files changed, 61 insertions(+), 24 deletions(-) diff --git a/LuaLibs/AddManData.lua b/LuaLibs/AddManData.lua index b029731..2548281 100644 --- a/LuaLibs/AddManData.lua +++ b/LuaLibs/AddManData.lua @@ -92,6 +92,10 @@ KEY_RIBS_TWO_STRANDS = "RibsHaveAll2Strands" -- Regioni con diverso numero di passate KEY_SHELL_NBR_DIFF = "ShellNbrDifference" KEY_INVERTED_CURVE = "CurveIsInverted" +KEY_SHELL_NBR_COASTING = "ShellNbrCoasting" +KEY_SHELL_NBR_WIPE = "ShellNbrWipe" +KEY_SHELL_NBR_WIPE_DIR = "ShellNbrWipeDir" +KEY_CLOSED_EXTRA_SHELL = "ExtraShellIsClosed" -- Parametri di macchina SEC_3DPRINTING = "3dPrinting" diff --git a/LuaLibs/CalcPaths.lua b/LuaLibs/CalcPaths.lua index 819809d..cb3f0c5 100644 --- a/LuaLibs/CalcPaths.lua +++ b/LuaLibs/CalcPaths.lua @@ -24,6 +24,7 @@ local function GetLayerParamsForPathCalc() LayerParams.dOffs = EgtGetInfo( s_nPartId, KEY_OFFSET_SLICE, 'd') LayerParams.nFloorNbr = EgtGetInfo( s_nPartId, KEY_FLOOR_NBR, 'i') LayerParams.vtSlicing = EgtGetInfo( s_nPartId, KEY_SLICING_DIR, 'v') + LayerParams.bPrintInvert = ( EgtGetInfo( s_nPartId, KEY_PRINT_DIRECTION, 'i') == PRINT_DIRECTION.CW) -- parametri costolature LayerParams.bRibsInvertOrder = EgtGetInfo( s_nPartId, KEY_RIBS_INVERT_ORDER, 'b') return LayerParams @@ -716,7 +717,7 @@ local function CreateShellNbrSurfaces( nGrp, nShellsNbr) end -- costruisco la surf local nSrfId, nCnt = EgtSurfFlatRegion( nSrfGrp, vCrvIds) - for nIdSrf = nSrfId + 1, nSrfId + nCnt - 2 do + for nIdSrf = nSrfId + 1, nSrfId + nCnt - 1 do EgtSurfFrAdd( nSrfId, nIdSrf) end EgtSetName( nSrfId, SHELL_NBR_SURF .. tostring( nDiff)) @@ -783,11 +784,19 @@ local function UpdateTotalShellSurf( nSrf, nCrv, dStrand, nGrpId) end --------------------------------------------------------------------- -local function ReorderExtraShells( nPathGrp, dStrand, vPtStart) +local function ReorderExtraShells( nPathGrp, dStrand, vPtStart, bPrintInvert) local vIds = EgtGetNameInGroup( nPathGrp, EXTRA_SHELL_CRV .. '*') - if not vIds then return end + if not vIds then return end + -- eventuale inversione di tutte le curve + if bPrintInvert then + for i = 1, #vIds do + EgtInvertCurve( vIds[i]) + EgtSetInfo( vIds[i], KEY_INVERTED_CURVE, 1) + end + end + -- cerco di creare percorsi local k = 0 -- indice da utilizzare per i nomi while #vIds > 0 do @@ -796,12 +805,14 @@ local function ReorderExtraShells( nPathGrp, dStrand, vPtStart) nCurrCrv = vIds[1] table.remove( vIds, 1) EgtSetName( nCurrCrv, EXTRA_SHELL_CRV .. tostring(k)) + local ptSCurr = EgtSP( nCurrCrv) local ptECurr = EgtEP( nCurrCrv) local nCnt = 0 -- se curva รจ chiusa if EgtCurveIsClosed( nCurrCrv) then ModifyStartPoint( nCurrCrv, vPtStart) + EgtSetInfo( nCurrCrv, KEY_CLOSED_EXTRA_SHELL, 1) -- setto a nil per ripartire subito con curva successiva nCurrCrv = nil end @@ -829,12 +840,12 @@ local function ReorderExtraShells( nPathGrp, dStrand, vPtStart) if dist( ptE, ptECurr) < 1.5 * dStrand then -- congiungo end-end EgtInvertCurve( vIds[j]) - EgtSetInfo( vIds[j], KEY_INVERTED_CURVE, 1) + EgtSetInfo( vIds[j], KEY_INVERTED_CURVE, EgtIf( bPrintInvert, 0, 1)) bLink = true elseif nCnt == 0 and dist( ptS, ptSCurr) < 1.5 * dStrand then -- congiungo start-start EgtInvertCurve( nCurrCrv) - EgtSetInfo( nCurrCrv, KEY_INVERTED_CURVE, 1) + EgtSetInfo( nCurrCrv, KEY_INVERTED_CURVE, EgtIf( bPrintInvert, 0, 1)) bLink = true end @@ -956,7 +967,7 @@ local function CalcExtraShellsPath( nMaxShellNbrDiff, nShellNbrGrp, nCrvGrpId, d for j = nCrvT + 1, nTrimCrv + nTrimCnt - 1 do EgtErase( j) end - ReorderExtraShells( nGrpId, LayerParams.dStrand, vPtStart) + ReorderExtraShells( nGrpId, LayerParams.dStrand, vPtStart, LayerParams.bPrintInvert) return end else @@ -972,7 +983,7 @@ local function CalcExtraShellsPath( nMaxShellNbrDiff, nShellNbrGrp, nCrvGrpId, d end -- riordino le curve appena create e se possibile creo percorsi chiusi - ReorderExtraShells( nGrpId, LayerParams.dStrand, vPtStart) + ReorderExtraShells( nGrpId, LayerParams.dStrand, vPtStart, LayerParams.bPrintInvert) end diff --git a/LuaLibs/CalcToolPath.lua b/LuaLibs/CalcToolPath.lua index 02e81e6..4da386b 100644 --- a/LuaLibs/CalcToolPath.lua +++ b/LuaLibs/CalcToolPath.lua @@ -39,8 +39,12 @@ local function GetLayerParamsForToolPathCalc() LayerParams.dTDiam = EgtGetInfo( s_nPartId, KEY_TOOL_DIAM, 'd') -- Parametri costolature LayerParams.bRibsLink = EgtGetInfo( s_nPartId, KEY_RIBS_LINK, 'b') + -- Parametri regioni con diverse passate + LayerParams.dShellNbrCoasting = EgtGetInfo( s_nPartId, KEY_SHELL_NBR_COASTING, 'd') + LayerParams.dShellNbrWipe = EgtGetInfo( s_nPartId, KEY_SHELL_NBR_WIPE, 'd') + LayerParams.dShellNbrWipeDir = EgtGetInfo( s_nPartId, KEY_SHELL_NBR_WIPE_DIR, 'd') - return LayerParams + return LayerParams end -------------------------------------------------------------------- @@ -175,7 +179,16 @@ local function AddLeadOut( nCrvId, LayerParams, nGrpId) end -------------------------------------------------------------------- -local function AddRetraction( nCrvId, dCoastingLen, dWipeLen, vtSlicing) +local function AddRetraction( nCrvId, LayerParams, dCoastingLen, dWipeLen) + + -- recupero i parametri per retrazione + local nType = EgtGetInfo( nCrvId, KEY_TYPE, 'i') + local bClosedExtraShell = EgtGetInfo( nCrvId, KEY_CLOSED_EXTRA_SHELL, 'b') or false + local dWipeDir = EgtIf( nType == TYPE.EXTRA_SHELL, LayerParams.dShellNbrWipeDir, 0) + if nType == TYPE.EXTRA_SHELL and not bClosedExtraShell then + dWipeLen = LayerParams.dShellNbrWipe + dCoastingLen = LayerParams.dShellNbrCoasting + end -- curva ausiliaria per generare correttamente wipe local nCopyId = EgtCopyGlob( nCrvId, nCrvId, GDB_IN.AFTER) @@ -206,21 +219,21 @@ local function AddRetraction( nCrvId, dCoastingLen, dWipeLen, vtSlicing) if dWipeLen > GEO.EPS_SMALL then -- se shell - local nWipeId - local nType = EgtGetInfo( nCrvId, KEY_TYPE, 'i') - if nType == TYPE.OUTER_SHELL or nType == TYPE.INNER_SHELL then - -- se shell + local nWipeId + if nType == TYPE.OUTER_SHELL or nType == TYPE.INNER_SHELL or bClosedExtraShell then + -- se shell o extra shell chiusa nWipeId = EgtCopyGlob( nCopyId, nCoastingId or nCrvId, GDB_IN.AFTER) EgtTrimCurveEndAtLen( nWipeId, dWipeLen) else -- se extra shell local bInverted = EgtGetInfo( nCrvId, KEY_INVERTED_CURVE, 'b') or false local vtDir = EgtEV( nCoastingId or nCrvId) - vtDir:rotate( vtSlicing, EgtIf( bInverted, 90, -90)) + local dAng = dWipeDir - 90 + vtDir:rotate( LayerParams.vtSlicing, EgtIf( bInverted, - dAng, dAng)) local ptS = EgtEP( nCoastingId or nCrvId) local ptE = ptS + vtDir * dWipeLen nWipeId = EgtCurveCompoFromPoints( EgtGetParent( nCrvId), {ptS, ptE}) - EgtRelocateGlob( nWipeId, nCoastingId or nCrvId, GDB_IN.AFTER) + EgtRelocateGlob( nWipeId, nCoastingId or nCrvId, GDB_IN.AFTER) end EgtSetName( nWipeId, WIPE_CRV) @@ -236,18 +249,18 @@ end local function AddRetractionOnLastCrv( nCrvId, nTpathGrpId, LayerParams) if LayerParams.nLeadOutType == LEAD_TYPE.NONE then - AddRetraction( nCrvId, LayerParams.dCoastingLen, LayerParams.dWipeLen, LayerParams.vtSlicing) + AddRetraction( nCrvId, LayerParams, LayerParams.dCoastingLen, LayerParams.dWipeLen) else local nLeadOutId = EgtGetLastInGroup( nTpathGrpId) local dLen = EgtCurveLength( nLeadOutId) if dLen > LayerParams.dCoastingLen - 500 * GEO.EPS_SMALL then -- coinvolge solo la curva di lead out local dNewCoastingLen = EgtIf( abs( LayerParams.dCoastingLen - dLen) < 500 * GEO.EPS_SMALL, dLen, LayerParams.dCoastingLen) -- verifico se interamente coinvolta - AddRetraction( nLeadOutId, dNewCoastingLen, 0.0, LayerParams.vtSlicing) + AddRetraction( nLeadOutId, LayerParams, dNewCoastingLen, 0.0) else -- coinvolge parte dell'ultima shell crv local dNewCoastingLen = LayerParams.dCoastingLen - dLen - local nCoastingId = AddRetraction( nCrvId, dNewCoastingLen, 0.0, LayerParams.vtSlicing) + local nCoastingId = AddRetraction( nCrvId, LayerParams, dNewCoastingLen, 0.0) EgtAddCurveCompoCurve( nCoastingId, nLeadOutId) end end @@ -482,7 +495,7 @@ local function AddRibsLeadOut( nCrv, nTPathGrp, nLoopsGrp, vtSlicing) -- verifico se la curva ha lunghezza sufficiente local dLen = EgtCurveLength( nCrvRef) local bSkip = ( dLen - dRibsLOLen - dRibsLOCoasting < - GEO.EPS_SMALL) - local vtE = EgtSV( nCrvRef) + local vtE = EgtEV( nCrv) -- primo tratto ( segue offset con flusso aperto) if dRibsLOLen > GEO.EPS_SMALL and not bSkip then @@ -513,8 +526,8 @@ local function AddRibsLeadOut( nCrv, nTPathGrp, nLoopsGrp, vtSlicing) -- terzo tratto ( diretto verso esterno con ugello chiuso) if dRibsLOWipe > GEO.EPS_SMALL then - local dAng = EgtIf( bInvert, 90, - 90) + dRibsLOWipeAng - vtE:rotate( vtSlicing, dAng) + local dAng = dRibsLOWipeAng - 90 + vtE:rotate( vtSlicing, EgtIf( bInvert, - dAng, dAng)) local ptFinal = ptE + vtE * dRibsLOWipe nWipe = EgtCurveCompoFromPoints( nTPathGrp, { ptE, ptFinal}) EgtRelocateGlob( nWipe, nCoasting or nCrvLO or nCrv, GDB_IN.AFTER) @@ -734,7 +747,8 @@ function CalcToolPath.Exec( nPartId) -- mi sposto dell'altezza layer EgtMove( nNewEntId, LayerParams.dLayHeight * LayerParams.vtSlicing, GDB_RT.GLOB) -- eventuale inversione - if EgtCurveIsClosed( nNewEntId) and LayerParams.bInvert then + local nType = EgtGetInfo( nNewEntId, KEY_TYPE, 'i') + if nType ~= TYPE.EXTRA_SHELL and LayerParams.bInvert then EgtInvertCurve( nNewEntId) end EgtModifyCurveExtrusion( nNewEntId, LayerParams.vtSlicing, GDB_RT.GLOB) @@ -744,6 +758,10 @@ function CalcToolPath.Exec( nPartId) -- aggiungo gli opportuni raccordi sulle shell complete local vIds = EgtGetNameInGroup( nTpathGrpId, SHELL_CRV .. '*') + local vIdsExtra = EgtGetNameInGroup( nTpathGrpId, EXTRA_SHELL_CRV .. '*') or {} + for i = 1, #vIdsExtra do + table.insert( vIds, vIdsExtra[i]) + end AddLink( vIds, nTpathGrpId, LayerParams.nLinkType, LayerParams.dLinkParam, LayerParams.dSPOffs, LayerParams.dStrand, LayerParams.vtSlicing) -- aggiungo gli opportuni raccondi sulle shell con numero diverso di passate @@ -789,9 +807,9 @@ function CalcToolPath.Exec( nPartId) -- aggiungo retrazione if nId == nFirstId then local dWipeLen = EgtIf( LayerParams.nLeadInType == LEAD_TYPE.NONE, LayerParams.dWipeLen, 0) - AddRetraction( nId, LayerParams.dCoastingLen, dWipeLen, LayerParams.vtSlicing) + AddRetraction( nId, LayerParams, LayerParams.dCoastingLen, dWipeLen) else - AddRetraction( nId, LayerParams.dCoastingLen, LayerParams.dWipeLen, LayerParams.vtSlicing) + AddRetraction( nId, LayerParams, LayerParams.dCoastingLen, LayerParams.dWipeLen) end end end diff --git a/LuaLibs/RunSlicing.lua b/LuaLibs/RunSlicing.lua index dd6bc28..334551f 100644 --- a/LuaLibs/RunSlicing.lua +++ b/LuaLibs/RunSlicing.lua @@ -122,6 +122,10 @@ local function LoadParams( sFile, nPartId) -- parametri per regioni con diverso numero di passate SetParamInfo( sFile, nPartId, SEC_DEFAULT, KEY_SHELL_NBR_DIFF, '0') + SetParamInfo( sFile, nPartId, SEC_DEFAULT, KEY_SHELL_NBR_COASTING, '0.0') + SetParamInfo( sFile, nPartId, SEC_DEFAULT, KEY_SHELL_NBR_WIPE, '0.0') + SetParamInfo( sFile, nPartId, SEC_DEFAULT, KEY_SHELL_NBR_WIPE_DIR, '0.0') + end ---------------------------------------------------------------------