From 7f472804958d370339f80fb4fa33ac86549c52c1 Mon Sep 17 00:00:00 2001 From: SaraP Date: Fri, 15 Jul 2022 17:26:52 +0200 Subject: [PATCH] 3dPrinting : - modificata definizione e gestione delle partenze sui layer. --- LuaLibs/AddManData.lua | 5 +-- LuaLibs/CalcPaths.lua | 80 ++++++++++++++++++++++++---------- LuaLibs/CalcSlices.lua | 9 ++-- LuaLibs/RunPartPositioning.lua | 27 +++++++----- LuaLibs/RunSlicing.lua | 15 ++----- 5 files changed, 85 insertions(+), 51 deletions(-) diff --git a/LuaLibs/AddManData.lua b/LuaLibs/AddManData.lua index 0ee4186..60ecab2 100644 --- a/LuaLibs/AddManData.lua +++ b/LuaLibs/AddManData.lua @@ -24,7 +24,7 @@ WIPE_CRV = "Wipe" LEAD_IN_CRV = "LeadIn" LEAD_OUT_CRV = "LeadOut" FRAME_PART = "FramePart" -START_POINT = "StartPoint" +START_GEOM = "Start" MIN_LEN = 0.1 MIN_AREA = 0.01 @@ -92,8 +92,7 @@ KEY_COEFF_Y = "CoeffY" KEY_SLICE_NBR = "SliceNbr" KEY_SLICE_Z = "SliceZ" KEY_SLICE_DELTAZ = "DeltaZ" -KEY_START_POINT = "StartPoint" - +KEY_SLICE_REAL_Z = "SliceRealZ" TYPE = { OUTER_SHELL = 1, diff --git a/LuaLibs/CalcPaths.lua b/LuaLibs/CalcPaths.lua index 46b0990..0d873c0 100644 --- a/LuaLibs/CalcPaths.lua +++ b/LuaLibs/CalcPaths.lua @@ -31,24 +31,44 @@ local function GetLayerParamsForPathCalc() end --------------------------------------------------------------------- -local function GetLayerStartPoint( nLayId) +local function GetLayerStartPoint( nLayId, vtSlicing) - local ptStart - -- recupero il punto di partenza usato nel layer precedente - local nPrev = EgtGetPrev( nLayId) - local nCrvGrp = EgtGetFirstNameInGroup( nPrev, CONTOUR_GRP..'*') - local nPathGrp = EgtGetFirstNameInGroup( nCrvGrp, PATH_GRP) - local nCrv = EgtGetFirstInGroup( nPathGrp) - if nCrv then - ptStart = EgtSP( nCrv, GDB_ID.ROOT) - else - ptStart = EgtGetInfo( s_nPartId, KEY_START_POINT, 'p') - end - return ptStart + -- recupero quota layer + local dZ = EgtGetInfo( nLayId, KEY_SLICE_REAL_Z, 'd') + local dDeltaZ = EgtGetInfo( nLayId, KEY_SLICE_DELTAZ, 'd') + local frSlicing = Frame3d( ORIG(), vtSlicing) + local ptOn = Point3d( 0, 0, dZ + dDeltaZ) + ptOn:toGlob( frSlicing) + + -- gruppo temporaneo dove salvo i risultati + local nGrpTmp = EgtGroup( nLayId) + + local vPtStart = {} + local nAuxGrp = EgtGetFirstNameInGroup( s_nPartId, LAY_AUX) + local nStartId = EgtGetFirstNameInGroup( nAuxGrp, START_GEOM) + while nStartId do + local nType = EgtGetType( nStartId) + -- se punto + if nType == GDB_TY.GEO_POINT then + table.insert( vPtStart, EgtSP( nStartId)) + else + -- se curva interseco con il piano + local nId, nCnt = EgtPlaneCurveInters( ptOn, vtSlicing, nStartId, nGrpTmp, GDB_RT.GLOB) + if nId then + for i = nId, nId + nCnt - 1 do + table.insert( vPtStart, EgtSP( i)) + end + end + end + nStartId = EgtGetNextName( nStartId, START_GEOM) + end + + EgtErase( nGrpTmp) + return vPtStart end --------------------------------------------------------------------- -local function GetPathsFromSurf( nSrfId, sName, nType, nGrpId, nLayId) +local function GetPathsFromSurf( nSrfId, sName, nType, nGrpId, vPtStart) local nChunks = EgtSurfFrChunkCount( nSrfId) for nC = 0, nChunks - 1 do @@ -71,11 +91,24 @@ local function GetPathsFromSurf( nSrfId, sName, nType, nGrpId, nLayId) return end - -- scelta start point - local ptStart = GetLayerStartPoint( nLayId) - EgtChangeClosedCurveStartPoint( nCrvId + nInd, ptStart, GDB_RT.GLOB) - end - end + -- cerco lo start point più vicino tra quelli possibili + if vPtStart and #vPtStart > 0 then + local nMinIdx = -1 + local dMinDist = GEO.INFINITO + for i = 1, #vPtStart do + local dDist = EgtPointCurveDist( vPtStart[i], nCrvId + nInd) + if dDist < dMinDist - 10 * GEO.EPS_SMALL then + dMinDist = dDist + nMinIdx = i + end + end + EgtChangeClosedCurveStartPoint( nCrvId + nInd, vPtStart[nMinIdx]) + else + -- se non ci sono start point disponibili prendo l'origine + EgtChangeClosedCurveStartPoint( nCrvId + nInd, Point3d( 0, 0, 0), GDB_RT.GLOB) + end + end + end end -------------------------------------------------------------------- @@ -474,7 +507,10 @@ function CalcPaths.Exec( nPartId, nStmId) for nIdx = 1, #vLayIds do local nRibsGrp = EgtGetFirstNameInGroup( vLayIds[nIdx], RIBS_GRP) - + + -- recupero gli start point per il layer + local vPtStart = GetLayerStartPoint( vLayIds[nIdx], LayerParams.vtSlicing) + -- scorro tutti i gruppi di contorni local nCrvGrpId = EgtGetFirstNameInGroup( vLayIds[nIdx], CONTOUR_GRP.."*") or GDB_ID.NULL while nCrvGrpId ~= GDB_ID.NULL do @@ -514,7 +550,7 @@ function CalcPaths.Exec( nPartId, nStmId) elseif not bExists then EgtOutLog( 'Warning : ExtOffset not possible (layer '..tostring( nIdx)..') - CalcPaths') else - GetPathsFromSurf( nSrfId, SHELL_CRV..'0', TYPE.OUTER_SHELL, nGrpId, vLayIds[nIdx]) + GetPathsFromSurf( nSrfId, SHELL_CRV..'0', TYPE.OUTER_SHELL, nGrpId, vPtStart) end EgtErase( nSrfId) @@ -536,7 +572,7 @@ function CalcPaths.Exec( nPartId, nStmId) elseif not bExists then EgtOutLog( 'Warning : IntOffset not possible (layer '..tostring( nIdx)..') - CalcPaths') else - GetPathsFromSurf( nSrfId, SHELL_CRV..tostring( nInd2), TYPE.INNER_SHELL, nGrpId, vLayIds[nIdx]) + GetPathsFromSurf( nSrfId, SHELL_CRV..tostring( nInd2), TYPE.INNER_SHELL, nGrpId, vPtStart) end EgtErase( nSrfId) end diff --git a/LuaLibs/CalcSlices.lua b/LuaLibs/CalcSlices.lua index d460db4..211fd09 100644 --- a/LuaLibs/CalcSlices.lua +++ b/LuaLibs/CalcSlices.lua @@ -54,7 +54,7 @@ local function ComputeMaxH( nStmId, frSlicing, HMax) end -------------------------------------------------------------------- -local function SlicingRibs( vtSlicing, dZmin) +local function SlicingRibs( vtSlicing) local nRibsShells = EgtGetInfo( s_nPartId, KEY_RIBS_SHELLS_NBR, 'i') or 0 if nRibsShells == 0 then return end @@ -76,7 +76,7 @@ local function SlicingRibs( vtSlicing, dZmin) local nLayId = EgtGetFirstNameInGroup( s_nPartId, SLICE_LAYER .. '*') while nLayId do -- recupero quota per slicing - local dZ = EgtGetInfo( nLayId, KEY_SLICE_Z, 'd') + local dZ = EgtGetInfo( nLayId, KEY_SLICE_REAL_Z, 'd') local dDeltaZ = EgtGetInfo( nLayId, KEY_SLICE_DELTAZ, 'd') -- creo gruppo per le costolature local nGrp = EgtGroup( nLayId) @@ -86,7 +86,7 @@ local function SlicingRibs( vtSlicing, dZmin) for i = 1, #vRibsIds do if EgtGetType( vRibsIds[i]) == GDB_TY.SRF_MESH then -- slicing costolatura - local nNewId, nPntCnt, nCrvCnt, nSrfCnt = EgtPlaneSurfTmInters( ORIG() + ( dZmin + dZ + dDeltaZ) * vtSlicing, vtSlicing, vRibsIds[i], nGrp, GDB_RT.GLOB, TOLER) + local nNewId, nPntCnt, nCrvCnt, nSrfCnt = EgtPlaneSurfTmInters( ORIG() + ( dZ + dDeltaZ) * vtSlicing, vtSlicing, vRibsIds[i], nGrp, GDB_RT.GLOB, TOLER) if nNewId then -- rimuovo punti for nId = nNewId, nNewId + nPntCnt -1 do @@ -177,6 +177,7 @@ function CalcSlices.Exec( nPartId, nStmId, HMax) local dDeltaZ = EgtIf( nLayCnt == 1, dDeltaZStart, 0) local dPosZ = vZSlices[nLayCnt]- dDeltaZ EgtSetInfo( nLayId, KEY_SLICE_Z, dPosZ - dZmin) + EgtSetInfo( nLayId, KEY_SLICE_REAL_Z, dPosZ) EgtSetInfo( nLayId, KEY_SLICE_NBR, nLayCnt) -- verifico se necessario ricalcolo @@ -382,7 +383,7 @@ function CalcSlices.Exec( nPartId, nStmId, HMax) end -- costolature - SlicingRibs( vtSlicing, dZmin) + SlicingRibs( vtSlicing) -- eventuale segnalazione errori if #vErr > 0 then diff --git a/LuaLibs/RunPartPositioning.lua b/LuaLibs/RunPartPositioning.lua index ea0d57a..34695ce 100644 --- a/LuaLibs/RunPartPositioning.lua +++ b/LuaLibs/RunPartPositioning.lua @@ -70,9 +70,6 @@ function RunPartPositioning.Exec() -- Rimuovo eventuale frame local nFrameId = EgtGetFirstNameInGroup( nAuxId, FRAME_PART) if nFrameId then EgtErase( nFrameId) end - -- Rimuovo eventuale start point - local nPtStartId = EgtGetFirstNameInGroup( nAuxId, KEY_START_POINT) - if nPtStartId then EgtErase( nPtStartId) end -- Recupero dati tavola (creando gruppo di lavoro temporaneo) local nQqqId = EgtAddMachGroup( 'qqq') @@ -164,13 +161,23 @@ function RunPartPositioning.Exec() EgtResetCurrMachGroup() - -- Creo lo start point - local ptStart = b3Solid:getCenter() - 0.6 * b3Solid:getDimY() * Y_AX() - 0.5 * b3Solid:getDimZ() * Z_AX() - nPtStartId = EgtPoint( nAuxId, ptStart, GDB_RT.GLOB) - if nPtStartId then - EgtSetName( nPtStartId, START_POINT) - EgtSetColor( nPtStartId, EgtStdColor( "RED")) - end + -- Porto punti/curve di inizio nel gruppo aux + local vStartId = EgtGetNameInGroup( nLayerId, START_GEOM) + if vStartId then + for j = 1, #vStartId do + EgtRelocateGlob( vStartId[j], nAuxId) + EgtSetColor( vStartId[j], EgtStdColor( "RED")) + end + else + -- se non ci sono punti/curve di inizio definiti e non ve ne sono nemmeno in aux, creo un punto + local vOldStart = EgtGetNameInGroup( nAuxId, START_GEOM) + if not vOldStart then + local ptStart = b3Solid:getCenter() - 0.6 * b3Solid:getDimY() * Y_AX() - 0.5 * b3Solid:getDimZ() * Z_AX() + nPtStartId = EgtPoint( nAuxId, ptStart, GDB_RT.GLOB) + EgtSetName( nPtStartId, START_GEOM) + EgtSetColor( nPtStartId, EgtStdColor( "RED")) + end + end -- Dichiaro pezzo posizionato EgtSetInfo( nPartId, KEY_PART_ON_TABLE, 1) diff --git a/LuaLibs/RunSlicing.lua b/LuaLibs/RunSlicing.lua index b8261c8..e57500b 100644 --- a/LuaLibs/RunSlicing.lua +++ b/LuaLibs/RunSlicing.lua @@ -104,17 +104,8 @@ local function LoadParams( sFile, nPartId) SetParamInfo( sFile, nPartId, SEC_DEFAULT, KEY_COASTING_LEN, '0.0') SetParamInfo( sFile, nPartId, SEC_DEFAULT, KEY_COASTING_FEED, '20000.0') SetParamInfo( sFile, nPartId, SEC_DEFAULT, KEY_WIPE_LEN, '0.0') - SetParamInfo( sFile, nPartId, SEC_DEFAULT, KEY_WIPE_FEEDPU, '0.9') - - -- recupero il punto iniziale e lo salvo tra i parametri - local ptStart = Point3d( 0, 0, 0) - local nAuxId = EgtGetFirstNameInGroup( nPartId, LAY_AUX) - local nPtStartId = EgtGetFirstNameInGroup( nAuxId or GDB_ID.NULL, START_POINT) - if nPtStartId then - ptStart = EgtSP( nPtStartId, GDB_ID.ROOT) - end - EgtSetInfo( nPartId, KEY_START_POINT, ptStart) - + SetParamInfo( sFile, nPartId, SEC_DEFAULT, KEY_WIPE_FEEDPU, '0.9') + -- parametri per costolature SetParamInfo( sFile, nPartId, SEC_DEFAULT, KEY_RIBS_OVERLAP, '0.0') SetParamInfo( sFile, nPartId, SEC_DEFAULT, KEY_RIBS_SHELLS_NBR, '0') @@ -238,7 +229,7 @@ function RunSlicing.Exec() -- Eventuale ripristino posizione solido RestoreSolidPosition( nPartId) - + -- Rimozione vecchi conti RemoveOldSlices( nPartId)