Aggiunta progetto iniziale
This commit is contained in:
@@ -0,0 +1,242 @@
|
||||
-- CalcSolids.lua by Egaltech s.r.l. 2022/03/30
|
||||
-- Calcolo percorsi di lavoro per Stampa 3d
|
||||
|
||||
-- Tabella per definizione modulo
|
||||
local CalcSolids = {}
|
||||
|
||||
-- Intestazioni
|
||||
require( 'EgtBase')
|
||||
|
||||
EgtOutLog( ' CalcSolids started', 1)
|
||||
|
||||
-- Dati
|
||||
local AMD = require( 'AddManData')
|
||||
|
||||
---------------------------------------------------------------------
|
||||
local function GetLayerParamsForSolidCalc()
|
||||
local nParamsGrp = EgtGetFirstNameInGroup( GDB_ID.ROOT, PARAMS_GRP)
|
||||
local LayerParams = {}
|
||||
LayerParams.bInvert = EgtGetInfo( nParamsGrp, KEY_PRINT_DIRECTION, 'b')
|
||||
LayerParams.dLayHeight = EgtGetInfo( nParamsGrp, KEY_SLICE_STEP, 'd')
|
||||
LayerParams.dStrand = EgtGetInfo( nParamsGrp, KEY_STRAND, 'd')
|
||||
LayerParams.nOrder = EgtGetInfo( nParamsGrp, KEY_PRINT_ORDER, 'i')
|
||||
return LayerParams
|
||||
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 ptB = ptA + dD2 * vtDir + dD3 * Z_AX()
|
||||
local ptC = ptB + dD4 * Z_AX()
|
||||
local ptD = ptA + dH * Z_AX()
|
||||
local ptE = ptD - 2 * dD1 * vtDir
|
||||
local ptF = ptC - 2 * ( dD1 + dD2) * vtDir
|
||||
local ptG = ptB - 2 * ( dD1 + dD2) * vtDir
|
||||
local ptH = ptA - 2 * dD1 * vtDir
|
||||
|
||||
local nId = EgtCurveCompoFromPoints( nSolidGrp, {ptA, ptB, ptC, ptD, ptE, ptF, ptG, ptH, ptA})
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
EgtErase( nSectE)
|
||||
return EgtSurfTmBySewing( nSolidGrp, { nSrfId, nSrfS, nSrfE})
|
||||
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
local function CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams, nParts)
|
||||
|
||||
local nCopyId = EgtCopyGlob( nCrvId, nSolidGrp)
|
||||
|
||||
-- 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.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 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)
|
||||
local nSectId = CreateSection( ptS, vtS, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp)
|
||||
EgtInvertCurve( nSectId)
|
||||
local nSrfId = EgtSurfTmSwept( nSolidGrp, nSectId, nId + nInd, false, 0.1)
|
||||
|
||||
if nSrfId then
|
||||
table.insert( vIdStm, nSrfId)
|
||||
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
|
||||
end
|
||||
|
||||
EgtErase( nSectId)
|
||||
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
|
||||
|
||||
---------------------------------------------------------------------
|
||||
function CalcSolids.Exec( nPartId)
|
||||
|
||||
local vLayIds = EgtGetNameInGroup( nPartId, SLICE_LAYER.."*")
|
||||
if not vLayIds then
|
||||
EgtOutBox( 'Error no slice', 'SolidCalc')
|
||||
return
|
||||
end
|
||||
|
||||
for nIdx = 1, #vLayIds do
|
||||
-- recupero i parametri relativi al layer
|
||||
local LayerParams = GetLayerParamsForSolidCalc()
|
||||
|
||||
-- scorro tutti i gruppi di contorni
|
||||
local nCrvGrpId = EgtGetFirstNameInGroup( vLayIds[ nIdx], CONTOUR_GRP.."*") or GDB_ID.NULL
|
||||
while nCrvGrpId ~= GDB_ID.NULL do
|
||||
|
||||
-- recupero il gruppo dei percorsi utensile
|
||||
local nTPathGrpId = EgtGetFirstNameInGroup( nCrvGrpId, TOOLPATH_GRP) or GDB_ID.NULL
|
||||
if nTPathGrpId == GDB_ID.NULL then
|
||||
EgtOutBox( 'Error no tool paths', 'SolidCalc')
|
||||
return
|
||||
end
|
||||
|
||||
-- recupero il gruppo dei soldi
|
||||
local nSolidGrpId = EgtGetFirstNameInGroup( nCrvGrpId, SOLID_GRP) or GDB_ID.NULL
|
||||
if nSolidGrpId == GDB_ID.NULL then
|
||||
nSolidGrpId = EgtGroup( nCrvGrpId)
|
||||
EgtSetName( nSolidGrpId, SOLID_GRP)
|
||||
else
|
||||
EgtEmptyGroup( nSolidGrpId)
|
||||
end
|
||||
|
||||
-- scorro le curve
|
||||
local nId = EgtGetFirstInGroup( nTPathGrpId)
|
||||
while nId do
|
||||
CreateSolidFromCurve( nId, nSolidGrpId, LayerParams)
|
||||
nId = EgtGetNext( nId)
|
||||
end
|
||||
|
||||
-- nascondo ExternCurve del gruppo
|
||||
local vExtCrvs = EgtGetNameInGroup( nCrvGrpId, OUTER_CRV)
|
||||
for nInd = 1, #vExtCrvs do
|
||||
EgtSetStatus( vExtCrvs[nInd], GDB_ST.OFF)
|
||||
end
|
||||
|
||||
--passo al gruppo di contorni successivo
|
||||
nCrvGrpId = EgtGetNextName( nCrvGrpId, CONTOUR_GRP.."*") or GDB_ID.NULL
|
||||
end
|
||||
if EgtProcessEvents( nIdx / #vLayIds * 100, 0) == 1 then
|
||||
EgtDraw()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
return CalcSolids
|
||||
Reference in New Issue
Block a user