From 39ac206ceeb35ccb279bc253e32b8fd10cde967c Mon Sep 17 00:00:00 2001 From: SaraP Date: Tue, 7 Jul 2026 11:48:04 +0200 Subject: [PATCH] =?UTF-8?q?3dPrinting=203.1g2=20:=20-=20aggiunta=20possibi?= =?UTF-8?q?lit=C3=A0=20di=20creare=20un=20unico=20percorso=20a=20partire?= =?UTF-8?q?=20da=20due=20shells=20-=20correzioni=20minori.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaLibs/AddManData.lua | 3 + LuaLibs/CalcPaths.lua | 150 ++++++++++++++++++++++++++++++--------- LuaLibs/CalcSlices.lua | 12 ++-- LuaLibs/CalcToolPath.lua | 16 +++++ Version.lua | 4 +- 5 files changed, 144 insertions(+), 41 deletions(-) diff --git a/LuaLibs/AddManData.lua b/LuaLibs/AddManData.lua index 8179165..e2872c8 100644 --- a/LuaLibs/AddManData.lua +++ b/LuaLibs/AddManData.lua @@ -88,6 +88,8 @@ KEY_WIPE_FEEDPU = 'WipeFeedPu' KEY_TOOL_DIAM = 'ToolDiam' KEY_MAX_STRANDH_FACTOR = 'MaxStrandHFactor' KEY_MIN_STRANDH_FACTOR = 'MinStrandHFactor' +KEY_JOIN_SHELLS = 'JoinShells' +KEY_SHELLS_JOINT_OVERLAP = 'ShellsJointOverlap' -- Solid Fill KEY_FLOOR_NBR = 'FloorCount' @@ -309,6 +311,7 @@ TABLE = 'Table' PART = 'Part' PRINT_SOLID = 'PrintSolid' LAY_MACH_START = 'MachStart' +JOINT_POSITION = 'JointPosition' LAY_RIBS = 'Ribs' LAY_AUX_SOLIDS = 'AuxSolids' LAY_SHELL_NBR = 'ShellNumber' diff --git a/LuaLibs/CalcPaths.lua b/LuaLibs/CalcPaths.lua index 2cc8b5c..1131839 100644 --- a/LuaLibs/CalcPaths.lua +++ b/LuaLibs/CalcPaths.lua @@ -34,6 +34,8 @@ local function GetLayerParamsForPathCalc() s_vtSlicing = EgtGetInfo( s_nPartId, KEY_SLICE_DIR, 'v') LayerParams.bPrintInvert = ( EgtGetInfo( s_nPartId, KEY_PRINT_DIRECTION, 'i') == PRINT_DIRECTION.CW) LayerParams.vPrintOrder = EgtGetInfo( s_nPartId, KEY_PRINT_ORDER, 'vi') or { 1, 2, 3, 4, 5, 6, 7, 8} + LayerParams.bJoinShells = EgtGetInfo( s_nPartId, KEY_JOIN_SHELLS, 'b') or false + LayerParams.dJointOverlap = EgtGetInfo( s_nPartId, KEY_SHELLS_JOINT_OVERLAP, 'd') or 0 -- parametri costolature LayerParams.bRibsInvertOrder = EgtGetInfo( s_nPartId, KEY_RIBS_INVERT_ORDER, 'b') or false LayerParams.bInvertRibsMergedShellLink = EgtGetInfo( s_nPartId, KEY_INVERT_RIBS_MERGED_SHELL_LINK, 'b') or false @@ -115,46 +117,42 @@ local function ComputeTrimSurf( nSrf, nGrpId, dStrand, dOverlap) end --------------------------------------------------------------------- -local function GetLayerStartPoint( nLayId) +local function GetReferenceOnLayer( vIds, nLayId) - -- creo un layer dove salvare i punti e le curve da usare come riferimento per le partenze dello slice corrente + -- creo un layer dove salvare i punti e le curve da usare come riferimento per lo slice corrente -- assegno un frame diretto come vtSlicing per poterlo utilizzare per il calcolo delle intersezioni con le curve del path ( fatte sul piano xy) - local nStartLayer = EgtGroup( nLayId, Frame3d( ORIG(), s_vtSlicing), GDB_RT.GLOB) - - local nMachStartGrp = EgtGetFirstNameInGroup( s_nPartId, LAY_MACH_START) + local nLayer = EgtGroup( nLayId, Frame3d( ORIG(), s_vtSlicing), GDB_RT.GLOB) + local ptOn = EgtGetInfo( nLayId, KEY_SLICE_POS, 'p') - local nStartId = EgtGetFirstInGroup( nMachStartGrp) - while nStartId do - local nType = EgtGetType( nStartId) + for i = 1, #vIds do + local nType = EgtGetType( vIds[i]) -- se punto lo salvo direttamente if nType == GDB_TY.GEO_POINT then - EgtCopyGlob( nStartId, nStartLayer) + EgtCopyGlob( vIds[i], nLayer) -- se curva la interseco con il piano elseif nType & GDB_FY.GEO_CURVE ~= 0 then - local nId, nCnt = EgtPlaneCurveInters( ptOn, s_vtSlicing, nStartId, nStartLayer, GDB_RT.GLOB) + local nId, nCnt = EgtPlaneCurveInters( ptOn, s_vtSlicing, vIds[i], nLayer, GDB_RT.GLOB) if not nId or nCnt == 0 then -- se non ha intersezioni salvo l'estremo della curva più vicino al piano - local ptS = EgtSP( nStartId, GDB_ID.ROOT) - local ptE = EgtEP( nStartId, GDB_ID.ROOT) + local ptS = EgtSP( vIds[i], GDB_ID.ROOT) + local ptE = EgtEP( vIds[i], GDB_ID.ROOT) local dDistS = abs(( ptS - ptOn) * s_vtSlicing) local dDistE = abs(( ptE - ptOn) * s_vtSlicing) if abs( dDistS - dDistE) < GEO.EPS_SMALL then - EgtPoint( nStartLayer, ptS, GDB_RT.GLOB) - EgtPoint( nStartLayer, ptE, GDB_RT.GLOB) + EgtPoint( nLayer, ptS, GDB_RT.GLOB) + EgtPoint( nLayer, ptE, GDB_RT.GLOB) elseif dDistS < dDistE then - EgtPoint( nStartLayer, ptS, GDB_RT.GLOB) + EgtPoint( nLayer, ptS, GDB_RT.GLOB) else - EgtPoint( nStartLayer, ptE, GDB_RT.GLOB) + EgtPoint( nLayer, ptE, GDB_RT.GLOB) end end end - - nStartId = EgtGetNext( nStartId) end - return nStartLayer + return nLayer end --------------------------------------------------------------------- @@ -355,6 +353,47 @@ local function AdjustTrimSurfExtraAngleChunks( nTrimSurf, dOffs, dStrand) end +--------------------------------------------------------------------- +local function JoinShells( vShells, vJointIds, nStartLay, nLayId, dStrand, dOverlap) + -- recupero punti e curve dove fare la giunzione sul layer corrente + local nJointsLay = GetReferenceOnLayer( vJointIds, nLayId) + + -- taglio le shell in corrispondenza del punto ottimale + local dTrimDist = 0.5 * dStrand * ( 1 - dOverlap / 100) + + local nShell1 = EgtCopyGlob( vShells[1], EgtGetParent( vShells[1])) + ModifyStartPoint( nShell1, nJointsLay) + EgtTrimCurveStartAtLen( nShell1, dTrimDist) + EgtTrimCurveEndAtLen( nShell1, EgtCurveLength( nShell1) - dTrimDist) + + local nShell2 = EgtCopyGlob( vShells[2], EgtGetParent( vShells[1])) + ModifyStartPoint( nShell2, nJointsLay) + EgtTrimCurveStartAtLen( nShell2, dTrimDist) + EgtTrimCurveEndAtLen( nShell2, EgtCurveLength( nShell2) - dTrimDist) + EgtInvertCurve( nShell2) + + -- verifico che il collegamento sia sensato + local ptS1 = EgtSP( nShell1, GDB_ID.ROOT) + local ptE1 = EgtEP( nShell1, GDB_ID.ROOT) + local ptS2 = EgtSP( nShell2, GDB_ID.ROOT) + local ptE2 = EgtEP( nShell2, GDB_ID.ROOT) + if dist( ptE1, ptS2) > 2 * dStrand or dist( ptS1, ptE2) > 2 * dStrand then + EgtOutLog( 'Warning : shell junction is not possibile (layer '.. EgtNumToString( s_nCurrIdx) ..') - CalcPaths') + EgtErase( { nShell1, nShell2, nJointsLay}) + return + end + + -- unisco + EgtAddCurveCompoLine( nShell1, ptS2, GDB_RT.GLOB) + EgtAddCurveCompoCurve( nShell1, nShell2) + EgtCloseCurveCompo( nShell1) + -- sistemo il punto iniziale + ModifyStartPoint( nShell1, nStartLay) + + EgtErase( vShells) + EgtErase( nJointsLay) +end + -------------------------------------------------------------------- ------------------------- INFILL ----------------------------------- -------------------------------------------------------------------- @@ -3533,6 +3572,8 @@ local function CalcRibsMergedShells( nSlicedRibsGrp, nPathGrp, LayerParams, nSta -- ripristino orientamento originale if EgtCurveIsClosed( nId) then local vtCrv = EgtCurveArea( nId) + local frLoc = EgtGetGlobFrame( nId) + vtCrv:toGlob( frLoc) if AreOppositeVectorApprox( vtCrv, s_vtSlicing) then EgtInvertCurve( nId) end @@ -3810,7 +3851,7 @@ local function UpdateExtraShellRetractionParamsAfterMerge( nCrv1, nCrv2, nCase) end --------------------------------------------------------------------- -local function ReorderExtraShells( nPathGrp, nStartLay, LayerParams) +local function ReorderExtraShells( nPathGrp, nStartLay, nMaxShellNbrDiff, LayerParams) local dAlpha = 1.2 @@ -3864,19 +3905,28 @@ local function ReorderExtraShells( nPathGrp, nStartLay, LayerParams) end end - -- verifico se le curve si possono chiudere + -- verifico se le curve si possono chiudere ed essere gestite come shell vShells = EgtGetNameInGroup( nPathGrp, sName) - for i = 1, #vShells do - if not EgtCurveIsClosed( vShells[i]) then - if dist( EgtSP( vShells[i]), EgtEP( vShells[i])) < dAlpha * dStrand + GEO.EPS_SMALL then - EgtCloseCurveCompo( vShells[i]) - -- ripristino orientamento originale - local vtCrv = EgtCurveArea( vShells[i]) - if AreOppositeVectorApprox( vtCrv, s_vtSlicing) then - EgtInvertCurve( vShells[i]) - UpdateInvertInfo( vShells[i]) - end + if #vShells == 1 then + if not EgtCurveIsClosed( vShells[1]) and dist( EgtSP( vShells[1]), EgtEP( vShells[1])) < dAlpha * dStrand + GEO.EPS_SMALL then + EgtCloseCurveCompo( vShells[1]) + end + + if EgtCurveIsClosed( vShells[1]) then + -- ripristino orientamento originale + local vtCrv = EgtCurveArea( vShells[1]) + local frLoc = EgtGetGlobFrame( vShells[1]) + vtCrv:toGlob( frLoc) + if AreOppositeVectorApprox( vtCrv, s_vtSlicing) then + EgtInvertCurve( vShells[1]) + UpdateInvertInfo( vShells[1]) end + -- sistemo punto iniziale + ModifyStartPoint( vShells[1], nStartLay) + -- modifico il nome per unificarlo alle shell + local nDelta = tonumber( sName:sub( #( EXTRA_SHELL_CRV) + 1)) + local nShellNbr = LayerParams.nShellsNbr - nMaxShellNbrDiff - 1 + nDelta + EgtSetName( vShells[1], SHELL_CRV .. tostring( nShellNbr)) end end @@ -4441,6 +4491,24 @@ function CalcPaths.Exec( nPartId) -- recupero i parametri per calcolo dei path local LayerParams = GetLayerParamsForPathCalc() local nSlicingType = EgtGetInfo( s_nPartId, KEY_SLICING_TYPE, 'i') + + -- recupero elementi di inizio percorso e di giunzione dal layer start + local nMachStartGrp = EgtGetFirstNameInGroup( s_nPartId, LAY_MACH_START) + local vMachStartIds = EgtGetAllInGroup( nMachStartGrp) + local vStartIds = {} + local vJointIds = {} + for i = 1, #vMachStartIds do + if EgtGetName( vMachStartIds[i]) == JOINT_POSITION or EgtGetInfo( vMachStartIds[i], KEY_ENTITY_NAME) == JOINT_POSITION then + table.insert( vJointIds, vMachStartIds[i]) + else + table.insert( vStartIds, vMachStartIds[i]) + end + end + if LayerParams.bJoinShells and #vJointIds == 0 then + EgtOutBox( 'No joint position for joining shells', 'Error', 'ERROR') + EgtOutLog( 'Error : no joint position for joining shells - CalcPaths') + return false + end -- scorro tutti i suoi layer for nIdx = 1, #vLayIds do @@ -4461,7 +4529,7 @@ function CalcPaths.Exec( nPartId) local nShellNbrSurfGrp = CreateShellNbrSurfaces( nShellNbrGrp, LayerParams.nShellsNbr) -- creo un layer con gli start da considerare per lo slice corrente - local nStartLay = GetLayerStartPoint( vLayIds[nIdx]) + local nStartLay = GetReferenceOnLayer( vStartIds, vLayIds[nIdx]) -- scorro tutti i gruppi di contorni local nCrvGrpId = EgtGetFirstNameInGroup( vLayIds[nIdx], CONTOUR_GRP.."*") or GDB_ID.NULL @@ -4576,7 +4644,23 @@ function CalcPaths.Exec( nPartId) bIgnoreMergedRibs = CalcRibsMergedShells( nRibsGrp, nGrpId, LayerParams, nStartLay) -- riordino extra shells - ReorderExtraShells( nGrpId, nStartLay, LayerParams) + ReorderExtraShells( nGrpId, nStartLay, nMaxShellNbrDiff, LayerParams) + + -- eventuale unione + if LayerParams.bJoinShells then + -- verifico che nel path ci siano solo due shell ( shell0 e shell1) + local vShells = EgtGetNameInGroup( nGrpId, SHELL_CRV .. '*') + local vExtraShells = EgtGetNameInGroup( nGrpId, EXTRA_SHELL_CRV .. '*') + if #vShells == 2 and #vExtraShells == 0 and EgtGetName( vShells[1]) == SHELL_CRV .. '0' and EgtGetName( vShells[2]) == SHELL_CRV .. '1' then + JoinShells( vShells, vJointIds, nStartLay, vLayIds[nIdx], LayerParams.dStrand, LayerParams.dJointOverlap) + else + if #vExtraShells > 0 then + EgtOutLog( 'Warning : shell junction is not possibile since there are extra shells (layer '.. EgtNumToString( s_nCurrIdx) ..') - CalcPaths') + else + EgtOutLog( 'Warning : in order to join shells there must be only two complete shells (layer '.. EgtNumToString( s_nCurrIdx) ..') - CalcPaths') + end + end + end end -- gestione solidi ausiliari ( se no floor o ceil) diff --git a/LuaLibs/CalcSlices.lua b/LuaLibs/CalcSlices.lua index 22c5a1b..8d6b95f 100644 --- a/LuaLibs/CalcSlices.lua +++ b/LuaLibs/CalcSlices.lua @@ -1503,19 +1503,19 @@ local function SlicingWithSolid( vStmIds, nSlicingType, dMaxH, vSlicingVal, vSli SlicingExtraObjects( nRibsLay, vSlicingDir, vSlicingVal, nSlicingType, TYPE.RIB, RIBS_CRV, RIBS_GRP, vStmIds) if EgtProcessEvents( EgtIf( PRINT, 100, 0) + ( #vLayers + 3) / nCounterTot * 100, 0) == 1 then return false end + -- solidi per regioni con diverso numero di passate + local nShellNbrLay = EgtGetFirstNameInGroup( s_nPartId, LAY_SHELL_NBR) + SlicingExtraObjects( nShellNbrLay, vSlicingDir, vSlicingVal, nSlicingType, TYPE.EXTRA_SHELL, SHELL_NBR_CRV, SHELL_NBR_GRP) + if EgtProcessEvents( EgtIf( PRINT, 100, 0) + ( #vLayers + 6) / nCounterTot * 100, 0) == 1 then return false end + local bSpiralVase = EgtGetInfo( s_nPartId, KEY_SPIRAL_VASE, 'b') or false if not bSpiralVase then -- infill if nSlicingType ~= SLICING_TYPE.MULTIPLANAR and nSlicingType ~= SLICING_TYPE.MULTIPLANAR_DEG45 and nSlicingType ~= SLICING_TYPE.MULTIPLANAR_HOR then PrepareInfill( vStmIds, vSlicingDir[1]) end - if EgtProcessEvents( EgtIf( PRINT, 100, 0) + ( #vLayers + 6) / nCounterTot * 100, 0) == 1 then return false end - - -- solidi per regioni con diverso numero di passate - local nShellNbrLay = EgtGetFirstNameInGroup( s_nPartId, LAY_SHELL_NBR) - SlicingExtraObjects( nShellNbrLay, vSlicingDir, vSlicingVal, nSlicingType, TYPE.EXTRA_SHELL, SHELL_NBR_CRV, SHELL_NBR_GRP) if EgtProcessEvents( EgtIf( PRINT, 100, 0) + ( #vLayers + 9) / nCounterTot * 100, 0) == 1 then return false end - + -- solidi ausiliari local nAuxSolidsLay = EgtGetFirstNameInGroup( s_nPartId, LAY_AUX_SOLIDS) SlicingExtraObjects( nAuxSolidsLay, vSlicingDir, vSlicingVal, nSlicingType, TYPE.AUX_SOLID, AUX_SOLIDS_CRV, AUX_SOLIDS_GRP) diff --git a/LuaLibs/CalcToolPath.lua b/LuaLibs/CalcToolPath.lua index 76e7858..94f2e87 100644 --- a/LuaLibs/CalcToolPath.lua +++ b/LuaLibs/CalcToolPath.lua @@ -2192,6 +2192,10 @@ local function SpiralVaseFullMultiPlanar( vLayIds, LayerParams) EgtOutBox( 'Error in spiral vase : layer ' .. tostring( nSliceNbr) .. ' has more than one toolpath', 'ToolPathCalc') return false end + if not EgtCurveIsClosed( vEntIds[1]) then + EgtOutBox( 'Error in spiral vase : open toolpath at layer ' .. tostring( nSliceNbr), 'ToolPathCalc') + return false + end local nNewEntId = EgtCopyGlob( vEntIds[1] or GDB_ID.NULL, nTpathGrpId, GDB_IN.LAST_SON) if nNewEntId then @@ -2481,6 +2485,10 @@ local function SpiralVaseFull( vLayIds, LayerParams) EgtOutBox( 'Error in spiral vase : layer ' .. tostring( nSliceNbr) .. ' has more than one toolpath', 'ToolPathCalc') return false end + if not EgtCurveIsClosed( vEntIds[1]) then + EgtOutBox( 'Error in spiral vase : open toolpath at layer ' .. tostring( nSliceNbr), 'ToolPathCalc') + return false + end local nNewEntId = EgtCopyGlob( vEntIds[1] or GDB_ID.NULL, nTpathGrpId, GDB_IN.LAST_SON) if nNewEntId then @@ -2713,6 +2721,10 @@ local function SpiralVasePartialMultiPlanar( vLayIds, LayerParams) EgtOutBox( 'Error in spiral vase : layer ' .. tostring( nSliceNbr) .. ' has more than one toolpath', 'ToolPathCalc') return false end + if not EgtCurveIsClosed( vEntIds[1]) then + EgtOutBox( 'Error in spiral vase : open toolpath at layer ' .. tostring( nSliceNbr), 'ToolPathCalc') + return false + end local nNewEntId = EgtCopyGlob( vEntIds[1] or GDB_ID.NULL, nTpathGrpId, GDB_IN.LAST_SON) if nNewEntId then @@ -2917,6 +2929,10 @@ local function SpiralVasePartial( vLayIds, LayerParams) EgtOutBox( 'Error in spiral vase : layer ' .. tostring( nSliceNbr) .. ' has more than one toolpath', 'ToolPathCalc') return false end + if not EgtCurveIsClosed( vEntIds[1]) then + EgtOutBox( 'Error in spiral vase : open toolpath at layer ' .. tostring( nSliceNbr), 'ToolPathCalc') + return false + end local nNewEntId = EgtCopyGlob( vEntIds[1] or GDB_ID.NULL, nTpathGrpId, GDB_IN.LAST_SON) if nNewEntId then diff --git a/Version.lua b/Version.lua index 4add404..8a45214 100644 --- a/Version.lua +++ b/Version.lua @@ -1,4 +1,4 @@ --- Version.lua by Egaltech s.r.l. 2026/07/01 +-- Version.lua by Egaltech s.r.l. 2026/07/07 -- Gestione della versione di 3dPrinting -VERSION = '3.1g1' \ No newline at end of file +VERSION = '3.1g2' \ No newline at end of file