3dPrinting :
- gestione regioni con numero diverso di passate.
This commit is contained in:
+521
-124
@@ -14,6 +14,7 @@ local AMD = require( 'AddManData')
|
||||
|
||||
---------------------------------------------------------------------
|
||||
local s_nPartId
|
||||
local s_dOffsCorr = 50 * GEO.EPS_SMALL
|
||||
|
||||
---------------------------------------------------------------------
|
||||
local function GetLayerParamsForPathCalc()
|
||||
@@ -28,6 +29,21 @@ local function GetLayerParamsForPathCalc()
|
||||
return LayerParams
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------
|
||||
local function ComputeSurfOffset( nSrf, nGrpId, dOffs)
|
||||
|
||||
local nCopySrf = EgtCopy( nSrf, nGrpId)
|
||||
local bOk = EgtSurfFrOffset( nCopySrf, dOffs)
|
||||
local bExists = EgtSurfFrChunkCount( nCopySrf) > 0
|
||||
if not bOk or not bExists then
|
||||
EgtErase( nCopySrf)
|
||||
nCopySrf = EgtCopyGlob( nSrf, nGrpId)
|
||||
bOk = EgtSurfFrOffset( nCopySrf, dOffs + 0.05)
|
||||
bExists = EgtSurfFrChunkCount( nCopySrf) > 0
|
||||
end
|
||||
return bOk, bExists, nCopySrf
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
local function GetLayerStartPoint( nLayId, vtSlicing)
|
||||
|
||||
@@ -65,19 +81,25 @@ local function GetLayerStartPoint( nLayId, vtSlicing)
|
||||
return vPtStart
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------
|
||||
local function ComputeSurfOffset( nSrf, nGrpId, dOffs)
|
||||
---------------------------------------------------------------------
|
||||
local function ModifyStartPoint( nCrvId, vPtStart)
|
||||
|
||||
local nCopySrf = EgtCopy( nSrf, nGrpId)
|
||||
local bOk = EgtSurfFrOffset( nCopySrf, dOffs)
|
||||
local bExists = EgtSurfFrChunkCount( nCopySrf) > 0
|
||||
if not bOk or not bExists then
|
||||
EgtErase( nCopySrf)
|
||||
nCopySrf = EgtCopyGlob( nSrf, nGrpId)
|
||||
bOk = EgtSurfFrOffset( nCopySrf, dOffs + 0.05)
|
||||
bExists = EgtSurfFrChunkCount( nCopySrf) > 0
|
||||
-- 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)
|
||||
if dDist < dMinDist - 10 * GEO.EPS_SMALL then
|
||||
dMinDist = dDist
|
||||
nMinIdx = i
|
||||
end
|
||||
end
|
||||
EgtChangeClosedCurveStartPoint( nCrvId, vPtStart[nMinIdx])
|
||||
else
|
||||
-- se non ci sono start point disponibili prendo l'origine
|
||||
EgtChangeClosedCurveStartPoint( nCrvId, Point3d( 0, 0, 0), GDB_RT.GLOB)
|
||||
end
|
||||
return bOk, bExists, nCopySrf
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
@@ -94,32 +116,17 @@ local function GetPathsFromSurf( nSrfId, sName, nType, nGrpId, vPtStart)
|
||||
-- se è loop interno lo inverto per averlo orientato in senso antiorario
|
||||
if nInd > 0 then
|
||||
EgtInvertCurve( nCrvId + nInd)
|
||||
end
|
||||
end
|
||||
|
||||
-- verifico soddisfi i requisiti (lunghezza e area)
|
||||
local dLen = EgtCurveLength( nCrvId + nInd)
|
||||
local _ , _ , dArea = EgtCurveArea( nCrvId + nInd)
|
||||
local _ , _ , dArea = EgtCurveArea( nCrvId + nInd)
|
||||
if dLen < MIN_LEN or dArea < MIN_AREA then
|
||||
EgtErase( nCrvId + nInd)
|
||||
return
|
||||
return
|
||||
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
|
||||
ModifyStartPoint( nCrvId + nInd, vPtStart)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -147,6 +154,10 @@ local function AddFloor( nSrfId, nGrpId, LayerParams, nFloorNbr)
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------
|
||||
--------------------------- RIBS -----------------------------------
|
||||
--------------------------------------------------------------------
|
||||
|
||||
--------------------------------------------------------------------
|
||||
local function TrimRibsOffset( nCrv, nOffs1, nOffs2, nOffsGrp, bIn)
|
||||
|
||||
@@ -310,41 +321,17 @@ local function HandleRibsIntersections( nRibsGrp, LayerParams, nOffsGrp, nRibsPa
|
||||
|
||||
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)
|
||||
local function ReorderRibs( nGrp, bInvertOrder, dStrand, nMaxNbr)
|
||||
|
||||
EgtSpInit()
|
||||
local vIds = EgtGetNameInGroup( nGrp, RIBS_CRV .. '*')
|
||||
if not vIds or #vIds == 0 then return end
|
||||
|
||||
local vSplitRibs = {}
|
||||
local vSPRibs = {}
|
||||
for i = 1, #vIds do
|
||||
@@ -374,6 +361,25 @@ local function ReorderRibs( nGrp, bInvertOrder)
|
||||
EgtRelocateGlob( vSplitRibs[i], nPrevId, GDB_IN.AFTER)
|
||||
end
|
||||
|
||||
-- sistemo nomi
|
||||
local kMax = nMaxNbr + 1
|
||||
for i = 1, nMaxNbr do
|
||||
local vIds = EgtGetNameInGroup( nGrp, RIBS_CRV .. tostring(i)) or {}
|
||||
for j = 2, #vIds do
|
||||
local ptM = EgtMP( vIds[j])
|
||||
local dDist = EgtPointCurveDist( ptM, vIds[j-1])
|
||||
if abs( dDist - 10) < 10 * GEO.EPS_SMALL then
|
||||
-- se le costolatura è vicina alla precedente avrà lo stesso nome
|
||||
EgtSetName( vIds[j], EgtGetName( vIds[j-1]))
|
||||
EgtRelocateGlob( vIds[j], vIds[j-1], GDB_IN.AFTER)
|
||||
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
|
||||
|
||||
--------------------------------------------------------------------------------------------
|
||||
@@ -439,7 +445,7 @@ local function ReorderRibsInters2Shells( nOffsGrp, dStrand)
|
||||
end
|
||||
|
||||
-- concateno le curve
|
||||
local nCrv, nCnt = EgtCurveCompoByChain( nOffsGrp, vOffs, ORIG())
|
||||
local nCrv, nCnt = EgtCurveCompoByChain( nOffsGrp, vOffs, ORIG())
|
||||
|
||||
local vIds = {}
|
||||
for i = nCrv, nCrv + nCnt - 1 do
|
||||
@@ -455,27 +461,70 @@ local function ReorderRibsInters2Shells( nOffsGrp, dStrand)
|
||||
table.remove( vIds, 1)
|
||||
EgtSetName( nCurrCrv, RIBS_CRV .. tostring(k))
|
||||
local pt = EgtEP( nCurrCrv)
|
||||
local _, dParE = EgtCurveDomain( 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])
|
||||
if vIds[j] ~= nCrv and not EgtCurveIsClosed(vIds[j]) then
|
||||
|
||||
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
|
||||
-- verifico se il collegamento è possibile
|
||||
local bAdd = false
|
||||
local bInvert = false
|
||||
local dDist, _, dParMinDist = EgtPointCurveDist( pt, vIds[j])
|
||||
if dDist < dStrand + 10 * GEO.EPS_SMALL then
|
||||
-- controllo che sia vicino ad uno degli estremi
|
||||
local dParS, dParE = EgtCurveDomain( vIds[j])
|
||||
if abs( dParMinDist - dParS) < 500 * GEO.EPS_SMALL then
|
||||
bAdd = true
|
||||
elseif abs( dParMinDist - dParE) < 500 * GEO.EPS_SMALL then
|
||||
bAdd = true
|
||||
-- è se necessaria inversione di vIds[j]
|
||||
bInvert = true
|
||||
end
|
||||
end
|
||||
|
||||
if not bAdd then
|
||||
-- check sullo start point di vIds[j]
|
||||
local dDist, _, dParMinDist = EgtPointCurveDist( EgtSP( vIds[j]), nCurrCrv)
|
||||
if dDist < dStrand + 10 * GEO.EPS_SMALL then
|
||||
bInvert = false
|
||||
-- controllo sia vicino all'end point della curva corrente
|
||||
if dParE - dParMinDist < 500 * GEO.EPS_SMALL then
|
||||
bAdd = true
|
||||
-- altrimenti può essere vicino allo start
|
||||
elseif dParMinDist < 500 * GEO.EPS_SMALL and nCnt == 0 then
|
||||
bAdd = true
|
||||
EgtInvertCurve( nCurrCrv)
|
||||
end
|
||||
end
|
||||
-- se non è aggiunto check con end point di vIds[j]
|
||||
if not bAdd then
|
||||
local dDist, _, dParMinDist = EgtPointCurveDist( EgtEP( vIds[j]), nCurrCrv)
|
||||
if dDist < dStrand + 10 * GEO.EPS_SMALL then
|
||||
bInvert = true
|
||||
if dParE - dParMinDist < 500 * GEO.EPS_SMALL then
|
||||
bAdd = true
|
||||
elseif dParMinDist < 500 * GEO.EPS_SMALL and nCnt == 0 then
|
||||
bAdd = true
|
||||
EgtInvertCurve( nCurrCrv)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if bAdd 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
|
||||
if bInvert then EgtInvertCurve( vIds[j]) end
|
||||
|
||||
-- aggiorno per collegamento successivo
|
||||
pt = EgtIf( bAddNoInvert, ptE, ptS)
|
||||
pt = EgtEP( vIds[j])
|
||||
_, dParE = EgtCurveDomain( vIds[j])
|
||||
nCurrCrv = vIds[j]
|
||||
-- elimino la curva dal vettore di curve da considerare
|
||||
table.remove( vIds, j)
|
||||
@@ -485,14 +534,7 @@ local function ReorderRibsInters2Shells( nOffsGrp, dStrand)
|
||||
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
|
||||
nCurrCrv = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -501,8 +543,10 @@ local function ReorderRibsInters2Shells( nOffsGrp, dStrand)
|
||||
ReassignInfo( nCrv, nCnt, vCopy)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------
|
||||
local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nStmId, nIdx)
|
||||
local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nIdx, nMaxStrandDiff)
|
||||
|
||||
local vRibs = EgtGetNameInGroup( nRibsGrp, RIBS_CRV .. '*')
|
||||
-- verifico se tutte le costolature vengono fatte con 2 passate
|
||||
@@ -515,8 +559,12 @@ local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nStmId, nIdx)
|
||||
end
|
||||
end
|
||||
|
||||
local nLast = EgtGetLastNameInGroup( nRibsGrp, RIBS_CRV .. '*')
|
||||
local sLastName = EgtGetName( nLast)
|
||||
local nMaxNbr = tonumber( string.sub( sLastName, 4))
|
||||
|
||||
-- calcolo gli offset
|
||||
local nOffsGrp = EgtGroup( nRibsGrp)
|
||||
local nOffsGrp = EgtGroup( nRibsGrp)
|
||||
for i = 1, #vRibs do
|
||||
local nShellsNbr = EgtGetInfo( vRibs[i], KEY_RIBS_SHELLS_NBR, 'i')
|
||||
local dOffs = ( nShellsNbr - 1) * LayerParams.dStrand / 2
|
||||
@@ -533,7 +581,7 @@ local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nStmId, nIdx)
|
||||
local nCrvGrp = EgtGetFirstNameInGroup( nSliceGrp, CONTOUR_GRP .. '*')
|
||||
while nCrvGrp do
|
||||
|
||||
-- creo o svuoto il gruppo
|
||||
-- creo o svuoto il gruppo
|
||||
local nRibsPathGrp = EgtGetFirstNameInGroup( nCrvGrp, RIBS_GRP)
|
||||
if not nRibsPathGrp then
|
||||
nRibsPathGrp = EgtGroup( nCrvGrp)
|
||||
@@ -544,21 +592,18 @@ local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nStmId, nIdx)
|
||||
end
|
||||
|
||||
-- creo le superfici con cui fare i trim
|
||||
local nSrf = EgtGetFirstNameInGroup( nCrvGrp, LAYER_SRF)
|
||||
local bOk, bExists, nSrfBase = ComputeSurfOffset( nSrf, nRibsPathGrp, - dOffs)
|
||||
if not bOk then
|
||||
EgtOutLog( 'Error on Offset for Ribs (layer '..tostring( nIdx)..') - CalcPaths')
|
||||
elseif not bExists then
|
||||
EgtOutLog( 'Warning: Ribs not possibile (layer '..tostring( nIdx)..') - CalcPaths')
|
||||
else
|
||||
local vSurfOffs = {}
|
||||
local nSrfBase = EgtGetFirstNameInGroup( nCrvGrp, TOT_SHELL_TRIM_SURF)
|
||||
if not nSrfBase then
|
||||
EgtOutLog( 'Warning : Ribs not possible (layer '..tostring( nIdx)..') - CalcPaths')
|
||||
else
|
||||
local vSurfOffs = {}
|
||||
for i = 1, #vRibs do
|
||||
local nOverlap = EgtGetInfo( vRibs[i], KEY_RIBS_OVERLAP, 'i')
|
||||
if not vSurfOffs[nOverlap] then
|
||||
local dNewOffs = ( 1 - nOverlap / 100) * LayerParams.dStrand
|
||||
local bOk, bExists, nSrfOffs = ComputeSurfOffset( nSrfBase, nRibsPathGrp, - dNewOffs)
|
||||
if bOk and bExists then
|
||||
vSurfOffs[ nOverlap] = nSrfOffs
|
||||
if not vSurfOffs[nOverlap] then
|
||||
local dNewOffs = nOverlap / 100 * LayerParams.dStrand
|
||||
local bOk, bExists, nSrfOffs = ComputeSurfOffset( nSrfBase, nRibsPathGrp, dNewOffs)
|
||||
if bOk then
|
||||
vSurfOffs[nOverlap] = nSrfOffs
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -566,19 +611,11 @@ local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nStmId, nIdx)
|
||||
-- gestisco eventuali intersezioni fra costolature
|
||||
local bInters = HandleRibsIntersections( nRibsGrp, LayerParams, nOffsGrp, nRibsPathGrp, bAllTwoStrands)
|
||||
EgtSetInfo( nRibsPathGrp or GDB_ID.NULL, KEY_RIBS_INTERS, bInters)
|
||||
EgtSetInfo( nRibsPathGrp or GDB_ID.NULL, KEY_RIBS_TWO_STRANDS, bAllTwoStrands)
|
||||
|
||||
-- riordino le costolature
|
||||
if bAllTwoStrands and bInters then
|
||||
-- gestione caso speciale di intersezione e 2 passate
|
||||
ReorderRibsInters2Shells( nRibsPathGrp, LayerParams.dStrand)
|
||||
else
|
||||
ReorderRibs( nRibsPathGrp, LayerParams.bRibsInvertOrder)
|
||||
end
|
||||
|
||||
EgtSetInfo( nRibsPathGrp or GDB_ID.NULL, KEY_RIBS_TWO_STRANDS, bAllTwoStrands)
|
||||
|
||||
-- eseguo il trim delle costole con la regione offsettata
|
||||
local vErased = {}
|
||||
local vOrderedRibs = EgtGetNameInGroup( nRibsPathGrp, RIBS_CRV .. '*')
|
||||
local tOldNewIds = {}
|
||||
local vOrderedRibs = EgtGetNameInGroup( nRibsPathGrp, RIBS_CRV ..'*')
|
||||
for i = 1, #vOrderedRibs do
|
||||
-- trim con superficie opportuna
|
||||
local nOverlap = EgtGetInfo( vOrderedRibs[i], KEY_RIBS_OVERLAP, 'i')
|
||||
@@ -586,33 +623,48 @@ local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nStmId, nIdx)
|
||||
-- la costolatura non è fattibile
|
||||
EgtOutLog( 'Warning: Ribs not possibile (layer '..tostring( nIdx)..') - CalcPaths')
|
||||
EgtErase( vOrderedRibs[i])
|
||||
vErased[vOrderedRibs[i]] = 1
|
||||
else
|
||||
local nCrv, nCnt = EgtTrimCurveWithRegion( vOrderedRibs[i], vSurfOffs[nOverlap], true, false)
|
||||
if nCnt == 0 then
|
||||
-- lo aggiungo nella tabella delle costolature eliminate
|
||||
vErased[vOrderedRibs[i]] = 1
|
||||
end
|
||||
tOldNewIds[ vOrderedRibs[i]] = {}
|
||||
|
||||
-- elimino tratti troppo corti
|
||||
for nId = nCrv, nCrv + nCnt - 1 do
|
||||
local dLen = EgtCurveLength( nId)
|
||||
for nInd = 0, nCnt - 1 do
|
||||
local dLen = EgtCurveLength( nCrv + nInd)
|
||||
if dLen < 10 * MIN_LEN then
|
||||
EgtErase( nId)
|
||||
-- lo aggiungo nella tabella delle costolature eliminate
|
||||
vErased[vOrderedRibs[i]] = 1
|
||||
EgtErase( nCrv + nInd)
|
||||
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)
|
||||
table.insert( tOldNewIds[ vOrderedRibs[i]], nCrv + nInd)
|
||||
if nInd > 0 then
|
||||
-- info split
|
||||
EgtSetInfo( nCrv + nInd, KEY_SPLIT_RIB, nCrv + nInd - 1)
|
||||
else
|
||||
-- aggiorno la info
|
||||
local nInfo = EgtGetInfo( nCrv + nInd, KEY_SPLIT_RIB, 'i')
|
||||
if nInfo then
|
||||
-- aggiorno info
|
||||
if #tOldNewIds[nInfo] > 0 then
|
||||
local nLast = #tOldNewIds[nInfo]
|
||||
EgtSetInfo( nCrv + nInd, KEY_SPLIT_RIB, tOldNewIds[nInfo][nLast])
|
||||
else
|
||||
-- se la costolatura da cui deriva è stata eliminata, tolgo l'info che le associava
|
||||
EgtRemoveInfo( nCrv + nInd, KEY_SPLIT_RIB)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- riordino le costolature
|
||||
if bAllTwoStrands and bInters then
|
||||
-- gestione caso speciale di intersezione e 2 passate
|
||||
ReorderRibsInters2Shells( nRibsPathGrp, LayerParams.dStrand)
|
||||
else
|
||||
ReorderRibs( nRibsPathGrp, LayerParams.bRibsInvertOrder, LayerParams.dStrand, nMaxNbr)
|
||||
end
|
||||
end
|
||||
|
||||
EgtErase( nSrfBase)
|
||||
if not EgtGetFirstNameInGroup( nRibsPathGrp, RIBS_CRV .. '*') then
|
||||
EgtErase( nRibsPathGrp)
|
||||
end
|
||||
@@ -620,8 +672,333 @@ local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nStmId, nIdx)
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
----------------- REGIONI CON DIVERSE PASSATE ----------------------
|
||||
--------------------------------------------------------------------
|
||||
local function CreateShellNbrSurfaces( nGrp, nShellsNbr)
|
||||
|
||||
if not nGrp then return end
|
||||
|
||||
local tDiffCrvs = {}
|
||||
local nMaxShellNbrDiff = 0
|
||||
local nCrvId = EgtGetFirstNameInGroup( nGrp, SHELL_NBR_CRV .. '*')
|
||||
while nCrvId do
|
||||
-- recupero info sul gap
|
||||
local nShellNbrDiff = EgtGetInfo( nCrvId, KEY_SHELL_NBR_DIFF, 'i')
|
||||
-- aggiorno eventuale massimo
|
||||
if nMaxShellNbrDiff < nShellNbrDiff then nMaxShellNbrDiff = nShellNbrDiff end
|
||||
-- salvo gli id delle curve
|
||||
if not tDiffCrvs[nShellNbrDiff] then
|
||||
tDiffCrvs[nShellNbrDiff] = { nCrvId}
|
||||
else
|
||||
table.insert( tDiffCrvs[nShellNbrDiff], nCrvId)
|
||||
end
|
||||
|
||||
nCrvId = EgtGetNextName( nCrvId, SHELL_NBR_CRV .. '*')
|
||||
end
|
||||
|
||||
-- eventuale correzione del numero massimo in base al numero di pareti interne
|
||||
nMaxShellNbrDiff = min( nMaxShellNbrDiff, nShellsNbr - 1)
|
||||
|
||||
-- costruisco per ogni valore la superficie complessiva
|
||||
local nSrfGrp = EgtGroup( nGrp)
|
||||
for nDiff = 1, nMaxShellNbrDiff do
|
||||
-- recupero gli id delle curve coinvolte
|
||||
local vCrvIds = {}
|
||||
for nG, vIds in pairs( tDiffCrvs) do
|
||||
if nG >= nDiff then
|
||||
for k = 1, #vIds do
|
||||
table.insert( vCrvIds, vIds[k])
|
||||
end
|
||||
end
|
||||
end
|
||||
-- costruisco la surf
|
||||
local nSrfId, nCnt = EgtSurfFlatRegion( nSrfGrp, vCrvIds)
|
||||
for nIdSrf = nSrfId + 1, nSrfId + nCnt - 2 do
|
||||
EgtSurfFrAdd( nSrfId, nIdSrf)
|
||||
end
|
||||
EgtSetName( nSrfId, SHELL_NBR_SURF .. tostring( nDiff))
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
local function ComputeMaxShellNbrDiff( nSrf, nShellNbrSurfGrp)
|
||||
|
||||
local nMaxShellNbrDiff = 0
|
||||
if nShellNbrSurfGrp then
|
||||
local nId = 1
|
||||
local nShellNbrSrf = EgtGetFirstNameInGroup( nShellNbrSurfGrp, SHELL_NBR_SURF .. tostring( nId))
|
||||
while nShellNbrSrf do
|
||||
-- se interessa la regione considerata aggiorno il nMaxShellNbrDiff
|
||||
if not EgtSurfFrTestExternal( nSrf, nShellNbrSrf) then
|
||||
nMaxShellNbrDiff = nId
|
||||
end
|
||||
|
||||
-- passo al successivo
|
||||
nId = nId + 1
|
||||
nShellNbrSrf = EgtGetFirstNameInGroup( nShellNbrSurfGrp, SHELL_NBR_SURF .. tostring( nId))
|
||||
end
|
||||
end
|
||||
|
||||
return nMaxShellNbrDiff
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
local function UpdateTotalShellSurf( nSrf, nCrv, dStrand, nGrpId)
|
||||
|
||||
local nCopyCrv = EgtCopyGlob( nCrv, nGrpId)
|
||||
-- creo percorso chiuso corrispondente
|
||||
if not EgtCurveIsClosed( nCrv) then
|
||||
local nCopy2 = EgtCopyGlob( nCrv, nGrpId)
|
||||
EgtInvertCurve( nCopy2)
|
||||
EgtAddCurveCompoCurve( nCopyCrv, nCopy2)
|
||||
end
|
||||
|
||||
local nOffsP = EgtOffsetCurveAdv( nCopyCrv, dStrand - s_dOffsCorr, GDB_OT.EXTEND)
|
||||
local vSrfIds = { nOffsP}
|
||||
if EgtCurveIsClosed( nCrv) then
|
||||
-- se curva è chiusa bisogna tenere conto dell'interno
|
||||
local nOffsM, nCnt = EgtOffsetCurveAdv( nCopyCrv, - dStrand + s_dOffsCorr)
|
||||
if nOffsM and nOffsM ~= GDB_ID.NULL then
|
||||
for nId = nOffsM, nOffsM + nCnt - 1 do
|
||||
table.insert( vSrfIds, nId)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local nSrfExtraShell = EgtSurfFlatRegion( nGrpId, vSrfIds)
|
||||
if not EgtSurfFrSubtract( nSrf, nSrfExtraShell) then
|
||||
EgtInvertSurf( nSrfExtraShell)
|
||||
EgtSurfFrSubtract( nSrf, nSrfExtraShell)
|
||||
end
|
||||
|
||||
EgtErase( nCopyCrv)
|
||||
for i = 1, #vSrfIds do
|
||||
EgtErase( vSrfIds[i])
|
||||
end
|
||||
EgtErase( nSrfExtraShell)
|
||||
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
function CalcPaths.Exec( nPartId, nStmId)
|
||||
local function JoinAndReorderExtraShells( nPathGrp, dStrand, vPtStart)
|
||||
|
||||
local vIds = EgtGetNameInGroup( nPathGrp, EXTRA_SHELL_CRV .. '*')
|
||||
if not vIds then return end
|
||||
|
||||
-- cerco di creare percorsi
|
||||
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, 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
|
||||
|
||||
-- scorro alla ricerca di una curva che posso collegare alla corrente
|
||||
while nCurrCrv do
|
||||
local bFound = false
|
||||
for j = 1, #vIds do
|
||||
|
||||
if not EgtCurveIsClosed( vIds[j]) then
|
||||
local ptS = EgtSP( vIds[j])
|
||||
local ptE = EgtEP( vIds[j])
|
||||
|
||||
if nCnt == 0 and dist( ptE, ptSCurr) < 1.5 * dStrand and EgtGetName( nCurrCrv) == EgtGetName( vIds[j]) then
|
||||
nCnt = nCnt + 1
|
||||
EgtRelocateGlob( vIds[j], nCurrCrv, GDB_IN.BEFORE)
|
||||
EgtSetName( vIds[j], EXTRA_SHELL_CRV .. tostring( k))
|
||||
table.remove( vIds, j)
|
||||
bFound = true
|
||||
break
|
||||
end
|
||||
|
||||
local bLink = dist( ptS, ptECurr) < 1.5 * dStrand
|
||||
|
||||
if dist( ptE, ptECurr) < 1.5 * dStrand then
|
||||
-- congiungo end-end
|
||||
EgtInvertCurve( vIds[j])
|
||||
EgtSetInfo( vIds[j], KEY_INVERTED_CURVE, 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)
|
||||
bLink = true
|
||||
end
|
||||
|
||||
if bLink then
|
||||
nCnt = nCnt + 1
|
||||
EgtRelocateGlob( vIds[j], nCurrCrv, GDB_IN.AFTER)
|
||||
EgtSetName( vIds[j], EXTRA_SHELL_CRV .. tostring( k))
|
||||
|
||||
-- aggiorno per collegamento successivo
|
||||
bFound = true
|
||||
nCurrCrv = vIds[j]
|
||||
ptSCurr = EgtSP( vIds[j])
|
||||
ptECurr = EgtEP( vIds[j])
|
||||
table.remove( vIds, j)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
-- se non ho più curve da collegare
|
||||
if not bFound then
|
||||
nCurrCrv = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- verifico se posso realizzare percorsi chiusi
|
||||
for i = 1, k do
|
||||
local vIds = EgtGetNameInGroup( nPathGrp, EXTRA_SHELL_CRV .. tostring(i))
|
||||
if #vIds == 2 then
|
||||
local ptS = EgtSP( vIds[1])
|
||||
local ptE = EgtEP( vIds[2])
|
||||
if dist( ptS, ptE) < 1.5 * dStrand then
|
||||
EgtAddCurveCompoLine( vIds[1], EgtSP( vIds[2]))
|
||||
EgtAddCurveCompoCurve( vIds[1], vIds[2])
|
||||
EgtCloseCurveCompo( vIds[1])
|
||||
-- modifico lo start point
|
||||
ModifyStartPoint( vIds[1], vPtStart)
|
||||
-- ripristino se necessario orientamento antiorario
|
||||
if EgtGetInfo( vIds[1], KEY_INVERTED_CURVE, 'b') then
|
||||
EgtInvertCurve( vIds[1])
|
||||
EgtSetInfo( vIds[1], KEY_INVERTED_CURVE, 0)
|
||||
end
|
||||
EgtSetInfo( vIds[1], KEY_CLOSED_EXTRA_SHELL, 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
local function VerifyExtraShellPath( nCrv, nGrpId, vtSlicing, dStrand)
|
||||
|
||||
-- verifico se è fattibile controllando se esiste offset
|
||||
local nOffs, nCnt = EgtOffsetCurveAdv( nCrv, - 0.5 * dStrand)
|
||||
if not nOffs or nOffs == GDB_ID.NULL then
|
||||
return false
|
||||
end
|
||||
for i = nOffs, nOffs + nCnt - 1 do
|
||||
EgtErase( i)
|
||||
end
|
||||
|
||||
-- controllo se è fattibile con una sola passata
|
||||
if EgtCurveIsClosed( nCrv) then
|
||||
local nGrpTmp = EgtGroup( nGrpId, Frame3d( ORIG(), vtSlicing))
|
||||
EgtRelocateGlob( nCrv, nGrpTmp)
|
||||
local dArea = EgtCurveAreaXY( nCrv)
|
||||
if dArea < 10 * GEO.EPS_SMALL then
|
||||
-- TODO curva generica
|
||||
local frLoc, dDimX, dDimY = EgtCurveMinAreaRectangleXY( nCrv)
|
||||
if dDimY < 10 * GEO.EPS_SMALL then
|
||||
local dZ = EgtSP( nCrv):getZ()
|
||||
-- creo la curva che corrisponde alla sigola passata
|
||||
local ptS = frLoc:getOrigin() - dDimX / 2 * frLoc:getVersX() + dZ * Z_AX()
|
||||
local ptE = frLoc:getOrigin() + dDimX / 2 * frLoc:getVersX() + dZ * Z_AX()
|
||||
if dist( ptS, ptE) > 5 then
|
||||
local nId = EgtCurveCompoFromPoints( nGrpTmp, { ptS, ptE})
|
||||
EgtErase( nCrv)
|
||||
EgtChangeId( nId, nCrv)
|
||||
end
|
||||
end
|
||||
end
|
||||
EgtRelocateGlob( nCrv, nGrpId, GDB_IN.LAST_SON)
|
||||
EgtErase( nGrpTmp)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
local function CalcExtraShellsPath( nMaxShellNbrDiff, nShellNbrGrp, nCrvGrpId, dOffs, LayerParams, nIdx, vPtStart)
|
||||
|
||||
local nGrpId = EgtGetFirstNameInGroup( nCrvGrpId, PATH_GRP)
|
||||
|
||||
-- recupero la superficie occupata dalle shell per trim
|
||||
local nSrfTrim = EgtGetFirstNameInGroup( nCrvGrpId, TOT_SHELL_TRIM_SURF)
|
||||
if not nSrfTrim then
|
||||
EgtOutLog( 'Warning : ExtraInnerShells not possible (layer '..tostring( nIdx)..') - CalcPaths')
|
||||
return
|
||||
end
|
||||
|
||||
for nInd = nMaxShellNbrDiff, 1, -1 do
|
||||
dOffs = dOffs + LayerParams.dStrand
|
||||
local nSrfDiff = EgtGetFirstNameInGroup( nShellNbrGrp, SHELL_NBR_SURF .. tostring( nInd))
|
||||
local nOuterCrv = EgtGetFirstNameInGroup( nCrvGrpId, OUTER_CRV)
|
||||
while nOuterCrv do
|
||||
local nCopy = EgtCopyGlob( nOuterCrv, nGrpId)
|
||||
|
||||
-- trim della curva con la regione con diverso numero di passate
|
||||
local nTrimCrv, nTrimCnt = EgtTrimCurveWithRegion( nCopy, nSrfDiff, false, false)
|
||||
if nTrimCnt ~= 0 then
|
||||
-- verifico se prima e ultima curva possono essere unite
|
||||
if nTrimCnt > 1 and AreSamePointApprox( EgtEP( nTrimCrv + nTrimCnt - 1), EgtSP( nTrimCrv)) then
|
||||
local nNewId = EgtCurveCompo( nGrpId, { nTrimCrv + nTrimCnt - 1, nTrimCrv})
|
||||
EgtChangeId( nNewId, nTrimCrv)
|
||||
nTrimCnt = nTrimCnt - 1
|
||||
end
|
||||
|
||||
for nCrvT = nTrimCrv, nTrimCrv + nTrimCnt - 1 do
|
||||
-- calcolo offset della curva ( è il percorso della shell)
|
||||
EgtModifyCurveExtrusion( nCrvT, LayerParams.vtSlicing)
|
||||
local nOffs, nOffsCnt = EgtOffsetCurveAdv( nCrvT, - dOffs)
|
||||
EgtErase( nCrvT)
|
||||
for nCrvOffs = nOffs, nOffs + nOffsCnt - 1 do
|
||||
-- trim con la regione già occupata dal altre shell
|
||||
local nCrv, nCnt = EgtTrimCurveWithRegion( nCrvOffs, nSrfTrim, true, true)
|
||||
if nCrv and nCnt ~= 0 then
|
||||
for nId = nCrv, nCrv + nCnt - 1 do
|
||||
local dLen = EgtCurveLength( nId)
|
||||
local bValid = VerifyExtraShellPath( nId, nGrpId, LayerParams.vtSlicing, LayerParams.dStrand)
|
||||
-- verifico se soddisfa vincolo sulla lunghezza
|
||||
if dLen > MIN_LEN and bValid then
|
||||
EgtModifyCurveExtrusion( nId, LayerParams.vtSlicing)
|
||||
EgtSetName( nId, EXTRA_SHELL_CRV .. tostring( nMaxShellNbrDiff - nInd + 1))
|
||||
EgtSetInfo( nId, KEY_TYPE, TYPE.EXTRA_SHELL)
|
||||
-- aggiorno la superficie occupata dalle shell con quella appena calcolata
|
||||
UpdateTotalShellSurf( nSrfTrim, nId, LayerParams.dStrand, nGrpId)
|
||||
-- se la superficie si annulla non è possibile realizzare altro, quindi cancello tutte le curve rimaste
|
||||
if EgtSurfFrChunkCount( nSrfTrim) == 0 then
|
||||
for j = nId + 1, nCrv + nCnt - 1 do
|
||||
EgtErase( j)
|
||||
end
|
||||
for j = nCrvT + 1, nTrimCrv + nTrimCnt - 1 do
|
||||
EgtErase( j)
|
||||
end
|
||||
JoinAndReorderExtraShells( nGrpId, LayerParams.dStrand, vPtStart)
|
||||
return
|
||||
end
|
||||
else
|
||||
EgtErase( nId)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
nOuterCrv = EgtGetNextName( nOuterCrv, OUTER_CRV)
|
||||
end
|
||||
end
|
||||
|
||||
-- riordino le curve appena create e se possibile creo percorsi chiusi
|
||||
JoinAndReorderExtraShells( nGrpId, LayerParams.dStrand, vPtStart)
|
||||
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
function CalcPaths.Exec( nPartId)
|
||||
|
||||
s_nPartId = nPartId
|
||||
|
||||
@@ -637,6 +1014,11 @@ function CalcPaths.Exec( nPartId, nStmId)
|
||||
for nIdx = 1, #vLayIds do
|
||||
|
||||
local nRibsGrp = EgtGetFirstNameInGroup( vLayIds[nIdx], RIBS_GRP)
|
||||
|
||||
-- regioni con diverso numero di passate
|
||||
local nShellNbrGrp = EgtGetFirstNameInGroup( vLayIds[nIdx], SHELL_NBR_GRP)
|
||||
CreateShellNbrSurfaces( nShellNbrGrp, LayerParams.nShellsNbr)
|
||||
local nShellNbrSurfGrp = EgtGetFirstGroupInGroup( nShellNbrGrp or GDB_ID.NULL)
|
||||
|
||||
-- recupero gli start point per il layer
|
||||
local vPtStart = GetLayerStartPoint( vLayIds[nIdx], LayerParams.vtSlicing)
|
||||
@@ -676,21 +1058,37 @@ function CalcPaths.Exec( nPartId, nStmId)
|
||||
end
|
||||
EgtErase( nSrfId)
|
||||
|
||||
-- pareti interne
|
||||
for nInd2 = 1, LayerParams.nShellsNbr - 1 do
|
||||
-- pareti interne complete
|
||||
local nMaxShellNbrDiff = ComputeMaxShellNbrDiff( nSrf, nShellNbrSurfGrp)
|
||||
for nInd = 1, LayerParams.nShellsNbr - 1 - nMaxShellNbrDiff do
|
||||
-- offset della superficie originale
|
||||
local bOk, bExists, nSrfId = ComputeSurfOffset( nSrf, nCrvGrpId, - dOffs - nInd2 * LayerParams.dStrand)
|
||||
dOffs = dOffs + LayerParams.dStrand
|
||||
local bOk, bExists, nSrfId = ComputeSurfOffset( nSrf, nCrvGrpId, - dOffs)
|
||||
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
|
||||
-- se offset riuscito, estraggo i contorni ( pareti interne)
|
||||
GetPathsFromSurf( nSrfId, SHELL_CRV..tostring( nInd2), TYPE.INNER_SHELL, nGrpId, vPtStart)
|
||||
GetPathsFromSurf( nSrfId, SHELL_CRV..tostring( nInd), TYPE.INNER_SHELL, nGrpId, vPtStart)
|
||||
end
|
||||
EgtErase( nSrfId)
|
||||
end
|
||||
|
||||
-- preparo superficie occupata dalle shell da usare per trim
|
||||
local bOkTrim, bExistsTrim, nSrfTrim = ComputeSurfOffset( nSrf, nCrvGrpId, - dOffs - LayerParams.dStrand + s_dOffsCorr)
|
||||
if not bOkTrim then
|
||||
EgtOutLog( 'Error on IntOffset (layer '..tostring( nIdx)..') - CalcPaths')
|
||||
elseif bExistsTrim then
|
||||
EgtSetName( nSrfTrim, TOT_SHELL_TRIM_SURF)
|
||||
EgtSetStatus( nSrfTrim, GDB_ST.OFF)
|
||||
end
|
||||
|
||||
-- eventuali pareti interne coinvolte dal diverso numero di passate
|
||||
if nMaxShellNbrDiff > 0 then
|
||||
CalcExtraShellsPath( nMaxShellNbrDiff, nShellNbrSurfGrp, nCrvGrpId, dOffs, LayerParams, nIdx, vPtStart)
|
||||
end
|
||||
|
||||
-- gestione eventuale floor
|
||||
if nIdx <= LayerParams.nFloorNbr then
|
||||
AddFloor( nSrf, nGrpId, LayerParams, nIdx)
|
||||
@@ -703,7 +1101,7 @@ function CalcPaths.Exec( nPartId, nStmId)
|
||||
|
||||
-- sistemo eventuali costolature
|
||||
if nRibsGrp then
|
||||
CalcRibsPaths( vLayIds[nIdx], nRibsGrp, LayerParams, nStmId, nIdx)
|
||||
CalcRibsPaths( vLayIds[nIdx], nRibsGrp, LayerParams, nIdx, nMaxStrandDiff)
|
||||
end
|
||||
|
||||
if EgtProcessEvents( nIdx / #vLayIds * 100, 0) == 1 then
|
||||
@@ -713,6 +1111,5 @@ function CalcPaths.Exec( nPartId, nStmId)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---------------------------------------------------------------------
|
||||
return CalcPaths
|
||||
|
||||
Reference in New Issue
Block a user