3dPrinting :

- correzioni nel collegamento tra ribs che terminano esattamente sul pezzo
- migliorie varie nei ribs.
This commit is contained in:
SaraP
2023-09-01 17:03:25 +02:00
parent a595fcdb98
commit d83b571883
2 changed files with 210 additions and 126 deletions
+120 -57
View File
@@ -1721,6 +1721,122 @@ local function HandleRibsIntersections( nRibsGrp, nOffsGrp, nRibsPathGrp, vtSlic
return bInters, bSpecialCase
end
---------------------------------------------------------------------
local function VerifySplitAssociation( nRib1, nRib2, dStrand)
local dDist1 = EgtPointCurveDist( EgtMP( nRib1), nRib2)
local dDist2 = EgtPointCurveDist( EgtMP( nRib2), nRib1)
-- verifico siano sufficientemente vicini
if dDist1 < dStrand + 10 * GEO.EPS_SMALL or dDist2 < dStrand + 10 * GEO.EPS_SMALL then
-- verifico nel caso di setti splittati dopo il trim che siano compatibili
local bUserLink = EgtGetInfo( nRib2, KEY_RIBS_USER_LINK, 'b') or false
local bSplitAfterTrim1 = EgtGetInfo( nRib1, KEY_SPLIT_AFTER_TRIM, 'b') or false
local bSplitAfterTrim2 = EgtGetInfo( nRib2, KEY_SPLIT_AFTER_TRIM, 'b') or false
if bSplitAfterTrim1 ~= bSplitAfterTrim2 then
if not bSplitAfterTrim2 and bSplitAfterTrim1 then
local nOrd = EgtGetInfo( nRib2, KEY_SPLIT_AFTER_TRIM_ORDER, 'i')
if nOrd == 0 then
return true
end
end
if bSplitAfterTrim1 then
local nOrd = EgtGetInfo( nRib1, KEY_SPLIT_AFTER_TRIM_ORDER, 'i')
local nTot = EgtGetInfo( nRib1, KEY_SPLIT_AFTER_TRIM_TOT, 'i')
if nOrd == nTot - 1 then
return true
end
end
else
return true
end
end
return false
end
---------------------------------------------------------------------
local function FindAssociatedSplitRibs( vRibs, dStrand)
local vAssociatedRibs = {}
-- vettore di flag per indicare se corrispondente elemento di vRibs è già stato associato ad un gruppo
local vUsed = {}
for i = 1, #vRibs do
vUsed[i] = false
end
local nCurrId = vRibs[1]
vUsed[1] = true
while nCurrId do
-- definisco un nuovo gruppo di setti associati
local vCurrGrp = { nCurrId}
local bFound = true
while bFound do
-- appena aggiungo un nuovo elemento al gruppo riparto a controllare tutti i setti non ancora associati per vedere quale posso aggiungere
bFound = false
for i = 2, #vRibs do
if bFound then break end
if not vUsed[i] then
for j = 1, #vCurrGrp do
if VerifySplitAssociation( vCurrGrp[j], vRibs[i], dStrand) then
bFound = true
table.insert( vCurrGrp, vRibs[i])
vUsed[i] = true
break
end
end
end
end
end
-- quando non ho più setti da aggiungere al gruppo corrente
-- riordino il gruppo appena individuato
if #vCurrGrp == 2 then
-- lascio l'ordinamento 1,2
EgtRelocateGlob( vCurrGrp[2], vCurrGrp[1], GDB_IN.AFTER)
elseif #vCurrGrp > 2 then
-- calcolo ordinamento ottimale con shorest path
EgtSpInit()
for i = 1, #vCurrGrp do
local ptS = EgtSP( vCurrGrp[i], GDB_ID.ROOT)
local ptE = EgtEP( vCurrGrp[i], GDB_ID.ROOT)
EgtSpAddPoint( ptS:getX(), ptS:getY(), ptS:getZ(), 0, 0, ptE:getX(), ptE:getY(), ptE:getZ(), 0, 0)
end
local vOrd = EgtSpCalculate( SHP_TY.OPEN)
EgtSpTerminate()
local vNewOrd = {}
for i = 1, #vOrd do
table.insert( vNewOrd, vCurrGrp[vOrd[i]])
end
-- riposiziono il primo elemento ( solo se è cambiato)
if vOrd[1] ~= 1 then
EgtRelocateGlob( vNewOrd[1], vCurrGrp[1], GDB_IN.AFTER)
end
-- riposiziono gli altri elementi
for i = 2, #vNewOrd do
EgtRelocateGlob( vNewOrd[i], vNewOrd[i-1], GDB_IN.AFTER)
end
vCurrGrp = vNewOrd
end
-- inserisco nella tabella il gruppo trovato
table.insert( vAssociatedRibs, vCurrGrp)
-- cerco il prossimo setto per un nuovo gruppo
nCurrId = nil
for i = 1, #vRibs do
if not vUsed[i] then
nCurrId = vRibs[i]
vUsed[i] = true
break
end
end
end
return vAssociatedRibs
end
---------------------------------------------------------------------
local function ReorderSplitRibs( vIds, bParamInvertOrder)
@@ -1758,58 +1874,8 @@ local function ReorderSplitRibs( vIds, bParamInvertOrder)
else
-- associo le curve dello split
local tAssociatedRibs = {}
while #tabVal > 0 do
local nCurrId = tabVal[1]
table.remove( tabVal, 1)
table.insert( tAssociatedRibs, { nCurrId})
local bCurrSplitAfterTrim = EgtGetInfo( nCurrId, KEY_SPLIT_AFTER_TRIM, 'b') or false
while nCurrId do
local ptCurr = EgtMP( nCurrId)
local bFound = false
for j = 1, #tabVal do
local dDist1 = EgtPointCurveDist( ptCurr, tabVal[j])
local dDist2 = EgtPointCurveDist( EgtMP( tabVal[j]), nCurrId)
if dDist1 < dStrand + 10 * GEO.EPS_SMALL or dDist2 < dStrand + 10 * GEO.EPS_SMALL then
-- verifico nel caso di setti splittati dopo il trim che siano compatibili
local bUserLink = EgtGetInfo( tabVal[j], KEY_RIBS_USER_LINK, 'b') or false
local bSplitAfterTrim = EgtGetInfo( tabVal[j], KEY_SPLIT_AFTER_TRIM, 'b') or false
if bSplitAfterTrim ~= bCurrSplitAfterTrim then
if not bCurrSplitAfterTrim and bSplitAfterTrim then
local nOrd = EgtGetInfo( tabVal[j], KEY_SPLIT_AFTER_TRIM_ORDER, 'i')
if nOrd == 0 then
bFound = true
end
end
if bCurrSplitAfterTrim then
local nOrd = EgtGetInfo( nCurrId, KEY_SPLIT_AFTER_TRIM_ORDER, 'i')
local nTot = EgtGetInfo( nCurrId, KEY_SPLIT_AFTER_TRIM_TOT, 'i')
if nOrd == nTot - 1 then
bFound = true
end
end
else
bFound = true
end
if bFound then
EgtRelocateGlob( tabVal[j], nCurrId, GDB_IN.AFTER)
nCurrId = tabVal[j]
bCurrSplitAfterTrim = bSplitAfterTrim
table.remove( tabVal, j)
table.insert( tAssociatedRibs[#tAssociatedRibs], nCurrId)
break
end
end
end
if not bFound then
nCurrId = nil
end
end
end
local tAssociatedRibs = FindAssociatedSplitRibs( tabVal, dStrand)
-- assegno splitid per gestire correttamente il link nel CalcToolPath
for i = 1, #tAssociatedRibs do
for j = 1, #tAssociatedRibs[i] do
@@ -1839,9 +1905,7 @@ local function ReorderSplitRibs( vIds, bParamInvertOrder)
else
-- ordinamento
if ( nTotParts % 2 == 0 and bInvertOrder and nLinkOrder % 2 ~= 0 ) or
( nTotParts % 2 == 0 and not bInvertOrder and nLinkOrder % 2 == 0) or
( nTotParts % 2 ~= 0 and nLinkOrder % 2 == 0) then
if ( bInvertOrder and nLinkOrder % 2 ~= 0 ) or ( not bInvertOrder and nLinkOrder % 2 == 0) then
local vLastGrp = tAssociatedRibs[#tAssociatedRibs]
local nPrevId = vLastGrp[#vLastGrp]
for i = #tAssociatedRibs - 1, 1, -1 do
@@ -1855,8 +1919,7 @@ local function ReorderSplitRibs( vIds, bParamInvertOrder)
-- direzione
if ( nTotParts % 2 == 0 and nLinkOrder > 0 and nLinkOrder < nTotParts - 1) or
( nTotParts % 2 ~= 0 and not bInvertOrder and nLinkOrder > 0) or
( nTotParts % 2 ~= 0 and bInvertOrder and nLinkOrder < nTotParts - 1) then
( nTotParts % 2 ~= 0 and nLinkOrder > 0) then
local vLastGrp = tAssociatedRibs[#tAssociatedRibs]
for j = 1, #vLastGrp do
EgtInvertCurve( vLastGrp[j])