c40fa8ff10
- correzioni nelle intersezioni costolature.
604 lines
24 KiB
Lua
604 lines
24 KiB
Lua
-- CalcPaths.lua by Egaltech s.r.l. 2022/06/28
|
|
-- Calcolo percorsi di lavoro per Stampa 3d
|
|
|
|
-- Tabella per definizione modulo
|
|
local CalcPaths = {}
|
|
|
|
-- Intestazioni
|
|
require( 'EgtBase')
|
|
|
|
EgtOutLog( ' CalcPaths started', 1)
|
|
|
|
-- Dati
|
|
local AMD = require( 'AddManData')
|
|
|
|
---------------------------------------------------------------------
|
|
local s_nPartId
|
|
|
|
---------------------------------------------------------------------
|
|
local function GetLayerParamsForPathCalc()
|
|
local LayerParams = {}
|
|
LayerParams.nShellsNbr = EgtGetInfo( s_nPartId, KEY_SHELLS_NBR, 'i')
|
|
LayerParams.dStrand = EgtGetInfo( s_nPartId, KEY_STRAND, 'd')
|
|
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')
|
|
-- parametri costolature
|
|
LayerParams.dRibsOverlap = EgtGetInfo( s_nPartId, KEY_RIBS_OVERLAP, 'd')
|
|
LayerParams.nRibsShellsNbr = EgtGetInfo( s_nPartId, KEY_RIBS_SHELLS_NBR, 'i')
|
|
LayerParams.bRibsInvertOrder = EgtGetInfo( s_nPartId, KEY_RIBS_INVERT_ORDER, 'b')
|
|
return LayerParams
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
local function GetLayerStartPoint( nLayId)
|
|
|
|
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
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
local function GetPathsFromSurf( nSrfId, sName, nType, nGrpId, nLayId)
|
|
|
|
local nChunks = EgtSurfFrChunkCount( nSrfId)
|
|
for nC = 0, nChunks - 1 do
|
|
-- estraggo i contorni
|
|
local nCrvId, nCrvCnt = EgtExtractSurfFrChunkLoops( nSrfId, nC, nGrpId)
|
|
for nInd = 0, nCrvCnt - 1 do
|
|
EgtSetName( nCrvId + nInd, sName)
|
|
EgtSetInfo( nCrvId + nInd, KEY_TYPE, nType)
|
|
|
|
-- se è loop interno lo inverto per averlo orientato in senso antiorario
|
|
if nInd > 0 then
|
|
EgtInvertCurve( nCrvId + nInd)
|
|
end
|
|
|
|
-- verifico soddisfi i requisiti (lunghezza e area)
|
|
local dLen = EgtCurveLength( nCrvId + nInd)
|
|
local _ , _ , dArea = EgtCurveArea( nCrvId + nInd)
|
|
if dLen < MIN_LEN or dArea < MIN_AREA then
|
|
EgtErase( nCrvId + nInd)
|
|
return
|
|
end
|
|
|
|
-- scelta start point
|
|
local ptStart = GetLayerStartPoint( nLayId)
|
|
EgtChangeClosedCurveStartPoint( nCrvId + nInd, ptStart, GDB_RT.GLOB)
|
|
end
|
|
end
|
|
end
|
|
|
|
--------------------------------------------------------------------
|
|
local function AddFloor( nSrfId, nGrpId, LayerParams, nFloorNbr)
|
|
|
|
-- local nSrfCopy = EgtCopyGlob( nSrfId, nGrpId)
|
|
-- local dOffs = 0.5 * LayerParams.dStrand - LayerParams.dOffs + LayerParams.nShellsNbr * LayerParams.dStrand
|
|
-- local dAng = 0
|
|
--
|
|
-- if EgtSurfFrOffset( nSrfCopy, - dOffs) and EgtSurfFrChunkCount( nSrfCopy) > 0 then
|
|
-- local nCrvId, nCnt = EgtGetSurfFrZigZagInfill( nSrfCopy, nGrpId, LayerParams.dStrand + 10 * GEO.EPS_SMALL, dAng, false, false)
|
|
-- for nInd = 0, nCnt - 1 do
|
|
-- local dLen = EgtCurveLength( nCrvId + nInd)
|
|
-- if dLen < MIN_LEN then
|
|
-- EgtErase( nCrvId + nInd)
|
|
-- else
|
|
-- EgtSetName( nCrvId + nInd, INFILL_CRV)
|
|
-- EgtSetInfo( nCrvId + nInd, KEY_TYPE, TYPE.INFILL)
|
|
-- end
|
|
-- end
|
|
-- EgtErase( nSrfCopy)
|
|
-- end
|
|
|
|
end
|
|
|
|
--------------------------------------------------------------------
|
|
local function TrimRibsOffset( nCrv, nOffs1, nOffs2, nOffsGrp, bIn)
|
|
|
|
local ptInt1 = EgtIP( nCrv, nOffs1, ORIG())
|
|
local ptInt2 = EgtIP( nCrv, nOffs2, ORIG())
|
|
local dPar1, dPar2
|
|
if ptInt1 then dPar1 = EgtCurveParamAtPoint( nCrv, ptInt1) end
|
|
if ptInt2 then dPar2 = EgtCurveParamAtPoint( nCrv, ptInt2) end
|
|
|
|
if dPar1 and dPar2 then
|
|
-- la curva viene spezzata in tre parti
|
|
if dPar1 > dPar2 then
|
|
dPar1, dPar2 = dPar2, dPar1
|
|
end
|
|
local nCopy = EgtCopyGlob( nCrv, nOffsGrp)
|
|
EgtTrimCurveEndAtParam( nCrv, dPar1)
|
|
EgtTrimCurveStartAtParam( nCopy, dPar2)
|
|
EgtSetInfo( nCopy, KEY_SPLIT_RIB, nCrv)
|
|
|
|
elseif dPar1 or dPar2 then
|
|
if bIn then
|
|
EgtTrimCurveEndAtParam( nCrv, dPar1 or dPar2)
|
|
else
|
|
EgtTrimCurveStartAtParam( nCrv, dPar1 or dPar2)
|
|
end
|
|
end
|
|
end
|
|
|
|
--------------------------------------------------------------------
|
|
-- Funzione che sistema le intersezioni fra costolature nel caso generico
|
|
local function AdjustRibsOffsetForIntersection( nCrv1, nCrv2, LayerParams, nOffsGrp, bIn)
|
|
|
|
-- calcolo gli offset della curva principale ( nCrv1) da usare per trim
|
|
local dOffs = ( LayerParams.nRibsShellsNbr - 1) * LayerParams.dStrand / 2
|
|
local nOffsM = EgtOffsetCurveAdv( nCrv1, - dOffs - ( 1 - LayerParams.dRibsOverlap / 100) * LayerParams.dStrand)
|
|
local nOffsP = EgtOffsetCurveAdv( nCrv1, dOffs + ( 1 - LayerParams.dRibsOverlap / 100) * LayerParams.dStrand)
|
|
local vSplit = {}
|
|
|
|
-- recupero gli offset della curva secondaria ( nCrv2)
|
|
local vOffs2 = EgtGetNameInGroup( nOffsGrp, EgtGetName( nCrv2))
|
|
-- trim degli offset della curva secondaria
|
|
for i = 1, #vOffs2 do
|
|
TrimRibsOffset( vOffs2[i], nOffsM, nOffsP, nOffsGrp, bIn)
|
|
end
|
|
|
|
EgtErase( nOffsM)
|
|
EgtErase( nOffsP)
|
|
end
|
|
|
|
--------------------------------------------------------------------
|
|
-- Funzione che sistema le intersezioni fra costolature nel caso di 2 passate
|
|
local function AdjustRibsOffsetForIntersection2Shells( nCrv1, nCrv2, LayerParams, nOffsGrp, bIn)
|
|
|
|
-- recupero gli offset delle due curve
|
|
local vOffs1 = EgtGetNameInGroup( nOffsGrp, EgtGetName( nCrv1))
|
|
local vOffs2 = EgtGetNameInGroup( nOffsGrp, EgtGetName( nCrv2))
|
|
|
|
local vCopy1 = {}
|
|
for i = 1, #vOffs1 do
|
|
local nId = EgtCopyGlob( vOffs1[i], nOffsGrp)
|
|
table.insert( vCopy1, nId)
|
|
end
|
|
|
|
-- trim degli offset di nCrv1
|
|
for i = 1, #vOffs1 do
|
|
-- trovo gli offset di nCrv2 coinvolti nell'intersezione
|
|
local vIds = {}
|
|
for j = 1, #vOffs2 do
|
|
local ptInt = EgtIP( vOffs1[i], vOffs2[j], ORIG())
|
|
if ptInt then table.insert( vIds, j) end
|
|
end
|
|
if #vIds > 0 then
|
|
local bInCrv1 = false
|
|
-- se viene trovata una sola intersezione devo calcolare bIn per nCrv1
|
|
if #vIds == 1 then
|
|
table.insert( vIds, EgtIf( vIds[1] == 1, 2, 1))
|
|
local ptInt = EgtIP( nCrv1, nCrv2, ORIG())
|
|
local dParInt = EgtCurveParamAtPoint( nCrv1, ptInt)
|
|
local _, dParE = EgtCurveDomain( nCrv1)
|
|
bInCrv1 = abs( dParInt - dParE) < 100 * GEO.EPS_SMALL
|
|
end
|
|
TrimRibsOffset( vOffs1[i], vOffs2[vIds[1]], vOffs2[vIds[2]], nOffsGrp, bInCrv1)
|
|
end
|
|
|
|
end
|
|
-- trim degli offset di nCrv2
|
|
for i = 1, #vOffs2 do
|
|
-- trovo gli offset di nCrv1 coinvolti nell'intersezione
|
|
local vIds = {}
|
|
for j = 1, #vCopy1 do
|
|
local ptInt = EgtIP( vOffs2[i], vCopy1[j], ORIG())
|
|
if ptInt then table.insert( vIds, j) end
|
|
end
|
|
if #vIds > 0 then
|
|
if #vIds == 1 then table.insert( vIds, EgtIf( vIds[1] == 1, 2, 1)) end
|
|
TrimRibsOffset( vOffs2[i], vCopy1[vIds[1]], vCopy1[vIds[2]], nOffsGrp, bIn)
|
|
end
|
|
end
|
|
|
|
for i = 1, #vCopy1 do
|
|
EgtErase( vCopy1[i])
|
|
end
|
|
|
|
end
|
|
|
|
--------------------------------------------------------------------
|
|
local function HandleRibsIntersections( nRibsGrp, LayerParams, nOffsGrp, nRibsPathGrp)
|
|
|
|
local nCrvGrp = EgtGetParent( nRibsPathGrp)
|
|
local nSrf = EgtGetFirstInGroup( nCrvGrp)
|
|
|
|
local vRibsIds = {}
|
|
local vOrigRibs = EgtGetNameInGroup( nRibsGrp, RIBS_CRV .. '*')
|
|
local nTrimmedRibsGrp = EgtGroup( nRibsPathGrp)
|
|
for i = 1, #vOrigRibs do
|
|
local nCopyId = EgtCopyGlob( vOrigRibs[i], nTrimmedRibsGrp)
|
|
local nCrv, nCnt = EgtTrimCurveWithRegion( nCopyId, nSrf, true, false)
|
|
for j = nCrv, nCrv + nCnt - 1 do
|
|
table.insert( vRibsIds, j)
|
|
end
|
|
-- copio i suoi offset nel RibsPathGrp
|
|
local vOffsRib = EgtGetNameInGroup( nOffsGrp, EgtGetName( vOrigRibs[i]))
|
|
for i = 1, #vOffsRib do
|
|
EgtCopyGlob( vOffsRib[i], nRibsPathGrp)
|
|
end
|
|
end
|
|
|
|
local bInters = false
|
|
local vSplit = {}
|
|
for i = 1, #vRibsIds do
|
|
-- verifico se interseca uno dei setti successivi
|
|
for j = i + 1, #vRibsIds do
|
|
local ptInt = EgtIP( vRibsIds[i], vRibsIds[j], ORIG())
|
|
if ptInt then
|
|
bInters = true
|
|
|
|
local dPar1 = EgtCurveParamAtPoint( vRibsIds[i], ptInt)
|
|
local dPar2 = EgtCurveParamAtPoint( vRibsIds[j], ptInt)
|
|
local _, dParE1 = EgtCurveDomain( vRibsIds[i])
|
|
local _, dParE2 = EgtCurveDomain( vRibsIds[j])
|
|
|
|
local bIn = abs( dPar1 - dParE1) < 50 * GEO.EPS_SMALL or abs( dPar2 - dParE2) < 50 * GEO.EPS_SMALL
|
|
local nCrv1 = vRibsIds[i] -- curva principale che non viene tagliata
|
|
local nCrv2 = vRibsIds[j] -- curve secondaria da modificare
|
|
if dPar1 < 50 * GEO.EPS_SMALL or abs( dPar1 - dParE1) < 50 * GEO.EPS_SMALL then
|
|
nCrv1, nCrv2 = nCrv2, nCrv1
|
|
end
|
|
|
|
if LayerParams.nRibsShellsNbr == 2 then
|
|
-- nel caso di 2 passate gestione speciale
|
|
AdjustRibsOffsetForIntersection2Shells( nCrv1, nCrv2, LayerParams, nRibsPathGrp, bIn)
|
|
else
|
|
AdjustRibsOffsetForIntersection( nCrv1, nCrv2, LayerParams, nRibsPathGrp, bIn)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
EgtErase( nTrimmedRibsGrp)
|
|
|
|
-- nel caso di intersezione sistemo i nomi in modo da gestire separatamente le costolature divise
|
|
if bInters then
|
|
local vRibsNames = {}
|
|
for i = 1, #vOrigRibs do
|
|
local sName = EgtGetName( vOrigRibs[i])
|
|
table.insert( vRibsNames, sName)
|
|
end
|
|
local kMax = tonumber( string.sub( vRibsNames[#vRibsNames], 4)) + 1
|
|
|
|
for i = 1, #vRibsNames do
|
|
local vIds = EgtGetNameInGroup( nRibsPathGrp, vRibsNames[i])
|
|
for j = 2, #vIds do
|
|
local ptM = EgtMP( vIds[j])
|
|
local dDist = EgtPointCurveDist( ptM, vIds[j-1])
|
|
if abs( dDist - LayerParams.dStrand) < 10 * GEO.EPS_SMALL then
|
|
-- se le costolatura è vicina alla precedente avrà lo stesso nome
|
|
EgtSetName( vIds[j], EgtGetName( vIds[j-1]))
|
|
else
|
|
-- se la costolatura dista troppo dalla precedente le cambio il nome
|
|
EgtSetName( vIds[j], RIBS_CRV .. tostring( kMax))
|
|
kMax = kMax + 1
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
return bInters
|
|
end
|
|
|
|
--------------------------------------------------------------------
|
|
-- Funzione che riordina le costolature nel caso generico
|
|
local function ReorderRibs( nGrp, bInvertOrder, nShells)
|
|
|
|
EgtSpInit()
|
|
local vIds = EgtGetNameInGroup( nGrp, RIBS_CRV .. '*')
|
|
local vSplitRibs = {}
|
|
for i = 1, #vIds do
|
|
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()
|
|
|
|
EgtRelocateGlob( vIds[vOrd[1]], nGrp, EgtIf( bInvertOrder, GDB_IN.LAST, GDB_IN.FIRST))
|
|
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
|
|
|
|
---------------------------------------------------------------------------------------------
|
|
-- Funzione che riordina le costolature nel caso di intersezioni e 2 passate
|
|
local function ReorderRibsInters2Shells( nOffsGrp, dStrand)
|
|
|
|
local vOffs = EgtGetNameInGroup( nOffsGrp, RIBS_CRV .. '*')
|
|
-- concateno le curve
|
|
local nCrv, nCnt = EgtCurveCompoByChain( nOffsGrp, vOffs, ORIG())
|
|
|
|
local vIds = {}
|
|
for i = nCrv, nCrv + nCnt - 1 do
|
|
EgtSetInfo( i, KEY_TYPE, TYPE.RIB)
|
|
table.insert( vIds, i)
|
|
end
|
|
|
|
local k = 0 -- indice da utilizzare per i nomi
|
|
while #vIds > 0 do
|
|
k = k + 1
|
|
-- prendo la prima tra le curve a disposizione
|
|
nCurrCrv = vIds[1]
|
|
table.remove( vIds, 1)
|
|
EgtSetName( nCurrCrv, RIBS_CRV .. tostring(k))
|
|
local pt = EgtEP( nCurrCrv)
|
|
local nCnt = 0
|
|
-- scorro alla ricerca di una curva che posso collegare alla corrente
|
|
while nCurrCrv do
|
|
local bFound = false
|
|
for j = 1, #vIds do
|
|
if vIds[j] ~= nCrv then
|
|
local ptS = EgtSP( vIds[j])
|
|
local ptE = EgtEP( vIds[j])
|
|
|
|
local bAddNoInvert = dist( pt, ptS) < dStrand + 10 * GEO.EPS_SMALL
|
|
local bAddWithInvert = dist( pt, ptE) < dStrand + 10 * GEO.EPS_SMALL
|
|
if bAddNoInvert or bAddWithInvert then
|
|
bFound = true
|
|
nCnt = nCnt + 1
|
|
EgtRelocateGlob( vIds[j], nCurrCrv, GDB_IN.AFTER)
|
|
EgtSetName( vIds[j], RIBS_CRV .. tostring( k))
|
|
-- eventuale inversione della curva
|
|
if bAddWithInvert then EgtInvertCurve( vIds[j]) end
|
|
|
|
-- aggiorno per collegamento successivo
|
|
pt = EgtIf( bAddNoInvert, ptE, ptS)
|
|
nCurrCrv = vIds[j]
|
|
-- elimino la curva dal vettore di curve da considerare
|
|
table.remove( vIds, j)
|
|
break
|
|
end
|
|
end
|
|
end
|
|
-- se non ho più curve da collegare
|
|
if not bFound then
|
|
-- se il percorso è fatto da una sola curva, riprovo a cercare collegamenti invertendola
|
|
if nCnt == 0 then
|
|
EgtInvertCurve( nCurrCrv)
|
|
pt = EgtEP( nCurrCrv)
|
|
nCnt = 1 -- per evitare di finire in un loop
|
|
else
|
|
nCurrCrv = nil
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
--------------------------------------------------------------------
|
|
local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nStmId)
|
|
|
|
-- calcolo gli offset
|
|
local dOffs = ( LayerParams.nRibsShellsNbr - 1) * LayerParams.dStrand / 2
|
|
local nOffsGrp = EgtGroup( nRibsGrp)
|
|
local vRibs = EgtGetNameInGroup( nRibsGrp, RIBS_CRV .. '*')
|
|
for i = 1, #vRibs do
|
|
for k = 0, LayerParams.nRibsShellsNbr - 1 do
|
|
local nNewId = EgtOffsetCurveAdv( vRibs[i], - dOffs + k * LayerParams.dStrand)
|
|
EgtSetName( nNewId, EgtGetName( vRibs[i]))
|
|
EgtSetInfo( nNewId, KEY_TYPE, TYPE.RIB)
|
|
EgtRelocateGlob( nNewId, nOffsGrp)
|
|
end
|
|
end
|
|
|
|
-- scorro i gruppi di curve
|
|
local nCrvGrp = EgtGetFirstNameInGroup( nSliceGrp, CONTOUR_GRP .. '*')
|
|
while nCrvGrp do
|
|
local nRibsPathGrp = EgtGetFirstNameInGroup( nCrvGrp, RIBS_GRP)
|
|
local nSrf = EgtGetFirstNameInGroup( nRibsPathGrp, LAYER_SRF)
|
|
if nSrf then
|
|
-- gestisco eventuali intersezioni fra costolature
|
|
local bInters = HandleRibsIntersections( nRibsGrp, LayerParams, nOffsGrp, nRibsPathGrp)
|
|
EgtSetInfo( nRibsPathGrp or GDB_ID.NULL, KEY_RIBS_INTERS, bInters)
|
|
|
|
-- riordino le costolature
|
|
if LayerParams.nRibsShellsNbr == 2 and bInters then
|
|
-- gestione caso speciale di intersezione e 2 passate
|
|
ReorderRibsInters2Shells( nRibsPathGrp, LayerParams.dStrand)
|
|
else
|
|
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)
|
|
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)
|
|
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
|
|
end
|
|
|
|
if not EgtGetFirstNameInGroup( nRibsPathGrp, RIBS_CRV .. '*') then
|
|
EgtErase( nRibsPathGrp)
|
|
end
|
|
nCrvGrp = EgtGetNextName( nCrvGrp, CONTOUR_GRP .. '*')
|
|
end
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
function CalcPaths.Exec( nPartId, nStmId)
|
|
|
|
s_nPartId = nPartId
|
|
|
|
local vLayIds = EgtGetNameInGroup( s_nPartId, SLICE_LAYER.."*")
|
|
if not vLayIds then
|
|
EgtOutBox( 'Error no slice', 'PathCalc')
|
|
return
|
|
end
|
|
|
|
-- recupero i parametri per calcolo dei path
|
|
local LayerParams = GetLayerParamsForPathCalc()
|
|
-- scorro tutti i suoi layer
|
|
for nIdx = 1, #vLayIds do
|
|
|
|
local nRibsGrp = EgtGetFirstNameInGroup( vLayIds[nIdx], RIBS_GRP)
|
|
|
|
-- scorro tutti i gruppi di contorni
|
|
local nCrvGrpId = EgtGetFirstNameInGroup( vLayIds[nIdx], CONTOUR_GRP.."*") or GDB_ID.NULL
|
|
while nCrvGrpId ~= GDB_ID.NULL do
|
|
|
|
-- verifico se il path e il solido sono già stati calcolati
|
|
local nGrpId = EgtGetFirstNameInGroup( nCrvGrpId, PATH_GRP) or GDB_ID.NULL
|
|
if nGrpId == GDB_ID.NULL then
|
|
nGrpId = EgtGroup( nCrvGrpId)
|
|
EgtSetName( nGrpId, PATH_GRP)
|
|
else
|
|
EgtEmptyGroup( nGrpId)
|
|
EgtSetStatus( nGrpId, GDB_ST.ON)
|
|
end
|
|
local nSolidGrpId = EgtGetFirstNameInGroup( nCrvGrpId, SOLID_GRP) or GDB_ID.NULL
|
|
if nSolidGrpId ~= GDB_ID.NULL then
|
|
EgtErase( nSolidGrpId)
|
|
end
|
|
|
|
-- recupero la superficie ottenuta dallo slicing
|
|
local nSrf = EgtGetFirstNameInGroup( nCrvGrpId, LAYER_SRF)
|
|
if nSrf then
|
|
-- esterno
|
|
local nSrfId = EgtCopyGlob( nSrf, nCrvGrpId)
|
|
local dOffs = 0.5 * LayerParams.dStrand - LayerParams.dOffs
|
|
local bOk = EgtSurfFrOffset( nSrfId, -dOffs)
|
|
local bExists = EgtSurfFrChunkCount( nSrfId) > 0
|
|
if not bOk then
|
|
EgtErase( nSrfId)
|
|
nSrfId = EgtCopyGlob( nSrf, nCrvGrpId)
|
|
local dNewOffs = dOffs - 0.05
|
|
bOk = EgtSurfFrOffset( nSrfId, -dNewOffs)
|
|
bExists = EgtSurfFrChunkCount( nSrfId) > 0
|
|
end
|
|
-- se offset riuscito, estraggo i contorni (pareti esterne)
|
|
if not bOk then
|
|
EgtOutLog( 'Error on ExtOffset (layer '..tostring( nIdx)..') - CalcPaths')
|
|
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])
|
|
end
|
|
EgtErase( nSrfId)
|
|
|
|
-- calcolo pareti interne
|
|
for nInd2 = 1, LayerParams.nShellsNbr - 1 do
|
|
-- offset della superficie originale
|
|
local nSrfId = EgtCopy( nSrf, nGrpId)
|
|
local bOk = EgtSurfFrOffset( nSrfId, - dOffs - nInd2 * LayerParams.dStrand)
|
|
local bExists = EgtSurfFrChunkCount( nSrfId) > 0
|
|
if not bOk then
|
|
EgtErase( nSrfId)
|
|
nSrfId = EgtCopyGlob( nSrf, nCrvGrpId)
|
|
bOk = EgtSurfFrOffset( nSrfId, -dOffs + 0.05 - nInd2 * LayerParams.dStrand)
|
|
bExists = EgtSurfFrChunkCount( nSrfId) > 0
|
|
end
|
|
-- se offset riuscito, estraggo i contorni ( pareti interne)
|
|
if not bOk then
|
|
EgtOutLog( 'Error on IntOffset (layer '..tostring( nIdx)..') - CalcPaths')
|
|
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])
|
|
end
|
|
EgtErase( nSrfId)
|
|
end
|
|
|
|
-- costolature
|
|
if nRibsGrp then
|
|
|
|
-- creo o svuoto il gruppo per le costolature
|
|
local nRibsPathGrp = EgtGetFirstNameInGroup( nCrvGrpId, RIBS_GRP)
|
|
if not nRibsPathGrp then
|
|
nRibsPathGrp = EgtGroup( nCrvGrpId)
|
|
EgtSetName( nRibsPathGrp, RIBS_GRP)
|
|
EgtSetStatus( nRibsPathGrp, GDB_ST.OFF)
|
|
else
|
|
EgtEmptyGroup( nRibsPathGrp)
|
|
end
|
|
|
|
-- calcolo superficie di offset da usare per le costolature
|
|
local nSrfId = EgtCopy( nSrf, nRibsPathGrp)
|
|
local dOffs = 0.5 * LayerParams.dStrand - LayerParams.dOffs + ( LayerParams.nShellsNbr - 1) * LayerParams.dStrand + ( 1 - LayerParams.dRibsOverlap / 100) * LayerParams.dStrand
|
|
local bOk = EgtSurfFrOffset( nSrfId, - dOffs)
|
|
local bExists = ( bOk and EgtSurfFrChunkCount( nSrfId) > 0)
|
|
if not bOk then
|
|
EgtErase( nSrfId)
|
|
nSrfId = EgtCopyGlob( nSrf, nRibsPathGrp)
|
|
bOk = EgtSurfFrOffset( nSrfId, - dOffs + 0.05)
|
|
bExists = ( bOk and EgtSurfFrChunkCount( nSrfId) > 0)
|
|
end
|
|
-- se non ho una superficie errore ed elimino il gruppo delle costolature
|
|
if not bOk then
|
|
EgtErase( nRibsPathGrp)
|
|
EgtOutLog( 'Error on Offset (Ribs) (layer '..tostring( nIdx)..') - CalcPaths')
|
|
elseif not bExists then
|
|
EgtErase( nRibsPathGrp)
|
|
EgtOutLog( 'Warning : Ribs not possible (layer '..tostring( nIdx)..') - CalcPaths')
|
|
end
|
|
|
|
end
|
|
|
|
-- gestione eventuale floor
|
|
if nIdx <= LayerParams.nFloorNbr then
|
|
AddFloor( nSrf, nGrpId, LayerParams, nIdx)
|
|
end
|
|
end
|
|
|
|
-- passo al gruppo di contorni successivo
|
|
nCrvGrpId = EgtGetNextName( nCrvGrpId, CONTOUR_GRP.."*") or GDB_ID.NULL
|
|
end
|
|
|
|
-- sistemo eventuali costolature
|
|
if nRibsGrp then
|
|
CalcRibsPaths( vLayIds[nIdx], nRibsGrp, LayerParams, nStmId)
|
|
end
|
|
|
|
if EgtProcessEvents( nIdx / #vLayIds * 100, 0) == 1 then
|
|
EgtDraw()
|
|
return
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
---------------------------------------------------------------------
|
|
return CalcPaths
|