- Correzioni e migliorie su pezzo di esempio
- Gestione avvio script solo quando eseguiti precedenti - Correzioni varie
This commit is contained in:
+94
-111
@@ -1,4 +1,4 @@
|
||||
-- CalcSolids.lua by Egaltech s.r.l. 2022/03/30
|
||||
-- CalcSolids.lua by Egaltech s.r.l. 2022/04/13
|
||||
-- Calcolo percorsi di lavoro per Stampa 3d
|
||||
|
||||
-- Tabella per definizione modulo
|
||||
@@ -23,18 +23,41 @@ local function GetLayerParamsForSolidCalc()
|
||||
return LayerParams
|
||||
end
|
||||
|
||||
|
||||
---------------------------------------------------------------------
|
||||
local function CalcSectionParams( dStrand, dH)
|
||||
local dL = dStrand
|
||||
local dLm = dStrand / 10
|
||||
local dHm = dH / 6
|
||||
-- recupero offset
|
||||
local nParamsGrp = EgtGetFirstNameInGroup( GDB_ID.ROOT, PARAMS_GRP)
|
||||
--local dOffs = EgtGetInfo( nParamsGrp, KEY_OFFSET_SLICE, 'd')
|
||||
dOffs = 0
|
||||
if dOffs and dOffs > 0 then
|
||||
-- calcolo area originale
|
||||
local dArea = ( dL * dH) - ( dLm * dHm)
|
||||
local dLM = ( dArea / dH) - ( dLm / 6)
|
||||
if dOffs / 2 <= ( dL - dLM) then
|
||||
dL = dL - dOffs / 2
|
||||
dLm = dL / 10
|
||||
dHm = (( dL * dH) - dArea) / dLm
|
||||
else
|
||||
EgtOutLog( 'Strand section not calculated on area. Too much overlap?')
|
||||
end
|
||||
end
|
||||
|
||||
local dD1 = 0.5 * dL - dLm
|
||||
local dD2 = 0.5 * dL - dD1
|
||||
local dD3 = dHm
|
||||
local dD4 = dH - 2 * dD3
|
||||
return dD1, dD2, dD3, dD4
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
local function CreateSection( ptS, vtDir, dStrand, dH, nSolidGrp)
|
||||
|
||||
ptS = ptS - dH * Z_AX()
|
||||
local dD1 = 0.5 * dStrand - dStrand / 10
|
||||
local dD2 = 0.5 * dStrand - dD1
|
||||
local dD3 = dH / 6
|
||||
local dD4 = dH - 2 * dD3
|
||||
|
||||
vtDir:rotate( Z_AX(), 90)
|
||||
|
||||
local ptA = ptS + dD1 * vtDir
|
||||
local dD1, dD2, dD3, dD4 = CalcSectionParams( dStrand, dH)
|
||||
local ptA = ptS - dH * Z_AX() + dD1 * vtDir
|
||||
local ptB = ptA + dD2 * vtDir + dD3 * Z_AX()
|
||||
local ptC = ptB + dD4 * Z_AX()
|
||||
local ptD = ptA + dH * Z_AX()
|
||||
@@ -48,138 +71,90 @@ local function CreateSection( ptS, vtDir, dStrand, dH, nSolidGrp)
|
||||
return nId
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
local function CreateHalfSection( ptS, vtDir, dStrand, dH, nSolidGrp)
|
||||
|
||||
local dD1, dD2, dD3, dD4 = CalcSectionParams( dStrand, dH)
|
||||
local ptA = ptS - dH * Z_AX() + dD1 * vtDir
|
||||
local ptB = ptA + dD2 * vtDir + dD3 * Z_AX()
|
||||
local ptC = ptB + dD4 * Z_AX()
|
||||
local ptD = ptA + dH * Z_AX()
|
||||
|
||||
local nId = EgtCurveCompoFromPoints( nSolidGrp, { ptS - dH * Z_AX(), ptA, ptB, ptC, ptD, ptS})
|
||||
|
||||
return nId
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
local function CloseSolid( nCrvId, nSrfId, nSolidGrp, LayerParams)
|
||||
|
||||
local ptS = EgtSP( nCrvId)
|
||||
local vtS = EgtSV( nCrvId)
|
||||
local nSectS = CreateSection( ptS, vtS, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp)
|
||||
local nSrfS = EgtSurfTmByRevolve( nSolidGrp, nSectS, ptS, Z_AX(), false, 0.1)
|
||||
EgtCutSurfTmPlane( nSrfS, ptS, EgtSV( nCrvId), true)
|
||||
vtS:rotate( Z_AX(), 90)
|
||||
local nSectS = CreateHalfSection( ptS, vtS, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp)
|
||||
local nSrfS = EgtSurfTmByScrewing( nSolidGrp, nSectS, ptS, Z_AX(), 180, 0, false, 0.1)
|
||||
EgtErase( nSectS)
|
||||
|
||||
local ptE = EgtEP( nCrvId)
|
||||
local vtE = EgtEV( nCrvId)
|
||||
local nSectE = CreateSection( ptE, vtE, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp)
|
||||
local nSrfE = EgtSurfTmByRevolve( nSolidGrp, nSectE, ptE, Z_AX(), false, 0.1)
|
||||
EgtCutSurfTmPlane( nSrfE, ptE, - EgtEV( nCrvId), true)
|
||||
|
||||
EgtErase( nSectS)
|
||||
vtE:rotate( Z_AX(), -90)
|
||||
local nSectE = CreateHalfSection( ptE, vtE, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp)
|
||||
local nSrfE = EgtSurfTmByScrewing( nSolidGrp, nSectE, ptE, Z_AX(), 180, 0, false, 0.1)
|
||||
EgtErase( nSectE)
|
||||
|
||||
return EgtSurfTmBySewing( nSolidGrp, { nSrfId, nSrfS, nSrfE})
|
||||
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
local function CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams, nParts)
|
||||
|
||||
local nCopyId = EgtCopyGlob( nCrvId, nSolidGrp)
|
||||
|
||||
local function CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams)
|
||||
|
||||
-- scelta del colore
|
||||
local nType = EgtGetInfo( nCrvId, KEY_TYPE, 'i')
|
||||
local Color = EgtStdColor( 'GRAY')
|
||||
if nType == TYPE.OUTER_SHELL then
|
||||
Color = EgtStdColor( 'ORANGE')
|
||||
elseif nType == TYPE.INNER_SHELL or nType == TYPE.LINK then
|
||||
Color = EgtStdColor( 'TEAL')
|
||||
elseif nType == TYPE.INNER_SHELL then
|
||||
Color = EgtStdColor( 'ORANGE')
|
||||
elseif nType == TYPE.LINK then
|
||||
Color = EgtStdColor( 'GRAY')
|
||||
elseif nType == TYPE.INFILL then
|
||||
Color = EgtStdColor( 'YELLOW')
|
||||
end
|
||||
|
||||
local nDefaultParts = EgtIf( nType == TYPE.LINK, 1, 10)
|
||||
if not nParts then
|
||||
nParts = nDefaultParts
|
||||
elseif nParts == nDefaultParts then
|
||||
nParts = nDefaultParts + 1
|
||||
end
|
||||
local nParts = EgtIf( nType == TYPE.LINK, 1, 10)
|
||||
|
||||
local nCopyId = EgtCopyGlob( nCrvId, nSolidGrp)
|
||||
local nId = EgtSplitCurve( nCopyId, nParts)
|
||||
local vIdStm = {}
|
||||
|
||||
|
||||
for nInd = 0, nParts - 1 do
|
||||
|
||||
if nType == TYPE.INFILL and nInd == 0 then
|
||||
EgtInvertCurve( nId + nInd)
|
||||
end
|
||||
|
||||
|
||||
local ptS = EgtSP( nId + nInd)
|
||||
local vtS = EgtSV( nId + nInd)
|
||||
vtS:rotate( Z_AX(), 90)
|
||||
local nSectId = CreateSection( ptS, vtS, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp)
|
||||
EgtInvertCurve( nSectId)
|
||||
local nSrfId = EgtSurfTmSwept( nSolidGrp, nSectId, nId + nInd, false, 0.1)
|
||||
|
||||
EgtErase( nSectId)
|
||||
if nSrfId then
|
||||
table.insert( vIdStm, nSrfId)
|
||||
nSrfId = CloseSolid( nId + nInd, nSrfId, nSolidGrp, LayerParams)
|
||||
else
|
||||
if nParts < 100 then
|
||||
-- cancello quando appena fatto e provo a spezzare la curva in un diverso numero di parti
|
||||
EgtErase( nSectId)
|
||||
for nInd3 = 0, nParts - 1 do
|
||||
EgtErase( nId + nInd3)
|
||||
end
|
||||
for nInd3 = 0, nInd - 1 do
|
||||
local nId2 = EgtGetLastInGroup( nSolidGrp)
|
||||
EgtErase( nId2)
|
||||
end
|
||||
local nNewParts = EgtIf( nParts == nDefaultParts, 5, nParts + 1)
|
||||
CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams, nNewParts)
|
||||
return
|
||||
else
|
||||
EgtOutBox( 'CalcSolid error', '')
|
||||
EgtErase( nSectId)
|
||||
for nInd3 = 0, nParts - 1 do
|
||||
EgtErase( nId + nInd3)
|
||||
end
|
||||
for nInd3 = 0, nInd - 1 do
|
||||
local nId2 = EgtGetLastInGroup( nSolidGrp)
|
||||
EgtErase( nId2)
|
||||
end
|
||||
return
|
||||
end
|
||||
EgtErase( nSectId)
|
||||
for nInd3 = 0, nParts - 1 do
|
||||
EgtErase( nId + nInd3)
|
||||
end
|
||||
for nInd3 = 0, nInd - 1 do
|
||||
local nId2 = EgtGetLastInGroup( nSolidGrp)
|
||||
EgtErase( nId2)
|
||||
end
|
||||
EgtOutBox( 'CalcSolid error', '')
|
||||
return
|
||||
end
|
||||
|
||||
EgtErase( nSectId)
|
||||
EgtSetColor( nSrfId, Color)
|
||||
EgtSetInfo( nSrfId, KEY_TYPE, nType)
|
||||
EgtErase( nId + nInd)
|
||||
end
|
||||
|
||||
-- se ho creato troppe parts unisco le superfici per ridurne il numero
|
||||
local vCrvIds = {}
|
||||
if nParts > nDefaultParts then
|
||||
local nGroups1 = nParts % nDefaultParts
|
||||
local nGroups2 = nDefaultParts - nGroups1
|
||||
local nElements1 = ceil( nParts / nDefaultParts)
|
||||
local nElements2 = floor( nParts / nDefaultParts)
|
||||
local nCnt = 0
|
||||
local nInd = 1
|
||||
while nInd <= #vIdStm do
|
||||
local nElements = EgtIf( nCnt < nGroups1, nElements1, nElements2)
|
||||
local vIds = { vIdStm[nInd]}
|
||||
local nFirstId = nId + nInd - 1
|
||||
for nId2 = 1, nElements - 1 do
|
||||
nInd = nInd + 1
|
||||
table.insert( vIds, vIdStm[nInd])
|
||||
EgtAddCurveCompoCurve( nFirstId, nId + nInd - 1)
|
||||
end
|
||||
|
||||
local nNewSrf = EgtSurfTmByTriangles( nSolidGrp, vIds)
|
||||
nInd = nInd + 1
|
||||
nCnt = nCnt + 1
|
||||
|
||||
table.insert( vCrvIds, nFirstId)
|
||||
vIdStm[nCnt] = nNewSrf
|
||||
end
|
||||
nParts = nDefaultParts
|
||||
else
|
||||
for nInd = 0, nParts - 1 do
|
||||
table.insert( vCrvIds, nId + nInd)
|
||||
end
|
||||
end
|
||||
|
||||
for nInd = 1, nParts do
|
||||
vIdStm[nInd] = CloseSolid( vCrvIds[nInd], vIdStm[nInd], nSolidGrp, LayerParams)
|
||||
EgtSetColor( vIdStm[nInd], Color)
|
||||
EgtSetInfo( vIdStm[nInd], KEY_TYPE, nType)
|
||||
EgtErase( vCrvIds[nInd])
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
@@ -206,7 +181,7 @@ function CalcSolids.Exec( nPartId)
|
||||
return
|
||||
end
|
||||
|
||||
-- recupero il gruppo dei soldi
|
||||
-- recupero il gruppo dei solidi
|
||||
local nSolidGrpId = EgtGetFirstNameInGroup( nCrvGrpId, SOLID_GRP) or GDB_ID.NULL
|
||||
if nSolidGrpId == GDB_ID.NULL then
|
||||
nSolidGrpId = EgtGroup( nCrvGrpId)
|
||||
@@ -215,7 +190,7 @@ function CalcSolids.Exec( nPartId)
|
||||
EgtEmptyGroup( nSolidGrpId)
|
||||
end
|
||||
|
||||
-- scorro le curve
|
||||
-- scorro le curve del percorso utensile
|
||||
local nId = EgtGetFirstInGroup( nTPathGrpId)
|
||||
while nId do
|
||||
CreateSolidFromCurve( nId, nSolidGrpId, LayerParams)
|
||||
@@ -227,12 +202,20 @@ function CalcSolids.Exec( nPartId)
|
||||
for nInd = 1, #vExtCrvs do
|
||||
EgtSetStatus( vExtCrvs[nInd], GDB_ST.OFF)
|
||||
end
|
||||
|
||||
|
||||
-- processo gli eventi
|
||||
if ( nIdx % 20) == 0 then
|
||||
EgtDraw()
|
||||
if EgtProcessEvents( nIdx / #vLayIds * 100, 0) == 1 then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
--passo al gruppo di contorni successivo
|
||||
nCrvGrpId = EgtGetNextName( nCrvGrpId, CONTOUR_GRP.."*") or GDB_ID.NULL
|
||||
end
|
||||
EgtDraw()
|
||||
if EgtProcessEvents( nIdx / #vLayIds * 100, 0) == 1 then
|
||||
EgtDraw()
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user