- corretta gestione degli offset per le paretine.

This commit is contained in:
Daniele Bariletti
2025-02-19 15:46:23 +01:00
parent 64b9a002be
commit 45aedbbbc7
+111 -26
View File
@@ -54,7 +54,7 @@ TOOL.tbIdLoop = {} -- tabella con gli id del loop su cui sta venendo costruita l
-- enum per il tipo di junction
_G.JUNC = JUNC
JUNC = {TrimStart = 0, TrimEnd = 1, And = 3}
JUNC = {TrimStart = 1, TrimEnd = 2, Angled = 3, TrimBoth = 4, TrimNone = 5}
function TOOL.ClearVariables()
TOOL.nId = nil
@@ -702,16 +702,16 @@ function TJunction(dAngBetween, dTh1, dTh2, nType, dLen1, dLen2, bOnLoop)
local dXOffset2 = 0
if not bOnLoop then bOnLoop = false end
if dAngBetween > 0 then
if nType == 1 then
if nType == JUNC.TrimStart then
-- trim start
local dDeltaStart = - dTh1 / sin(dAngBetween)
dLen2 = dLen2 + dDeltaStart
dXOffset2 = dDeltaStart
dXOffset2 = - dDeltaStart
-- extend end
local dDeltaEnd = dTh1 * tan(90- math.abs(dAngBetween))
dLen1 = dLen1 + dDeltaEnd
dXOffset1 = dDeltaEnd
elseif nType == 2 then
elseif nType == JUNC.TrimEnd then
-- trim end
local dDeltaEnd = - dTh2 / sin(dAngBetween)
dLen1 = dLen1 + dDeltaEnd
@@ -719,22 +719,22 @@ function TJunction(dAngBetween, dTh1, dTh2, nType, dLen1, dLen2, bOnLoop)
-- extend start
local dDeltaStart = dTh2 * tan(90- math.abs(dAngBetween))
dLen2 = dLen2 + dDeltaStart
dXOffset2 = dDeltaStart
dXOffset2 = - dDeltaStart
end
else
-- qui sto estendendo le lunghezze, infatti gli angoli sono nergativi e quindi anche il loro seno
if nType == 1 then
if nType == JUNC.TrimStart then
-- il trim start diventa un extend end
local dDelta = - dTh2 / sin(dAngBetween)
if not bOnLoop then dDelta = dDelta - dTh1 * tan(90 - math.abs(dAngBetween)) end
dLen1 = dLen1 + dDelta
dXOffset1 = dDelta
local dDeltaEnd = - dTh2 / sin(dAngBetween)
if not bOnLoop then dDeltaEnd = dDeltaEnd - dTh1 * tan(90 - math.abs(dAngBetween)) end
dLen1 = dLen1 + dDeltaEnd
dXOffset1 = dDeltaEnd
-- accorcio lo start
local dDeltaStart = 0
if not bOnLoop then dDeltaStart = - dTh2 * tan(90- math.abs(dAngBetween)) end
dLen2 = dLen2 + dDeltaStart
dXOffset2 = dDeltaStart
elseif nType == 2 then
dXOffset2 = - dDeltaStart
elseif nType == JUNC.TrimEnd then
-- il trim end diventa un extend start
local dDeltaStart = dTh1 / sin(dAngBetween)
if not bOnLoop then dDeltaStart = dDeltaStart + dTh2 * tan(90 - math.abs(dAngBetween)) end
@@ -853,6 +853,92 @@ function TOOL.CreateCircularHole(nPart, ptCenter, dDiam)
TOOL.AddInLoopToPart(nInLoopLay)
end
local function CalcPrevJunction(tbInfo, nIdPrev)
-- junction type: 1.trim start, 2.trim end, 3.Angled, 4.TrimBoth, 5.TrimNone
local JunctionResult
local JuncPrev = EgtGetInfo(nIdPrev, "JunctionType", "i")
local JuncCurr = tbInfo.nJunctionType
if nIdPrev == GDB_ID.NULL then return JuncCurr end
-- l'ordine gerarchico è TrimNone > TrimBoth > TrimStart > TrimEnd > Angled
if JuncCurr == JUNC.TrimNone then
if JuncPrev ~= JUNC.TrimNone then
JunctionResult = JUNC.TrimStart
else
JunctionResult = JUNC.Angled
end
elseif JuncCurr == JUNC.TrimBoth then
if JuncPrev ~= JUNC.TrimBoth then
JunctionResult = JUNC.TrimStart
else
JunctionResult = JUNC.Angled
end
elseif JuncCurr == JUNC.TrimStart then
if JuncPrev == JUNC.TrimBoth then
JunctionResult = JUNC.TrimEnd
else
JunctionResult = JUNC.TrimStart
end
elseif JuncCurr == JUNC.TrimEnd then
if JuncPrev == JUNC.TrimNone or JuncPrev == JUNC.TrimStart then
JunctionResult = JUNC.TrimStart
else
JunctionResult = JUNC.TrimEnd
end
elseif JuncCurr == JUNC.Angled then
if JuncPrev == JUNC.TrimNone then
JunctionResult = JUNC.TrimStart
elseif JuncPrev == JUNC.TrimBoth then
JunctionResult = JUNC.TrimEnd
else
JunctionResult = JuncPrev
end
end
return JunctionResult
end
local function CalcNextJunction(tbInfo, nIdNext)
-- junction type: 1.trim start, 2.trim end, 3.Angled, 4.TrimBoth, 5.TrimNone
local JunctionResult
local JuncNext = EgtGetInfo(nIdNext, "JunctionType", "i")
local JuncCurr = tbInfo.nJunctionType
if nIdNext == GDB_ID.NULL then return JuncCurr end
-- l'ordine gerarchico è TrimNone > TrimBoth > TrimStart > TrimEnd > Angled
if JuncCurr == JUNC.TrimNone then
if JuncNext ~= JUNC.TrimNone then
JunctionResult = JUNC.TrimStart
else
JunctionResult = JUNC.Angled
end
elseif JuncCurr == JUNC.TrimBoth then
if JuncNext ~= JUNC.TrimBoth then
JunctionResult = JUNC.TrimEnd
else
JunctionResult = JUNC.Angled
end
elseif JuncCurr == JUNC.TrimStart then
if JuncNext == JUNC.TrimNone then
JunctionResult = JUNC.TrimEnd
else
JunctionResult = JUNC.TrimStart
end
elseif JuncCurr == JUNC.TrimEnd then
if JuncNext == JUNC.TrimBoth or JuncNext == JUNC.TrimStart then
JunctionResult = JUNC.TrimStart
else
JunctionResult = JUNC.TrimEnd
end
elseif JuncCurr == JUNC.Angled then
if JuncNext == JUNC.TrimNone then
JunctionResult = JUNC.TrimEnd
elseif JuncNext == JUNC.TrimBoth then
JunctionResult = JUNC.TrimStart
else
JunctionResult = JuncNext
end
end
return JunctionResult
end
function TOOL.CreateParetina(nEdgeId, tbInfo, dPairAngCorr)
local tbIdLoopTC = {}
-- se ho chiamato la funzione senza passare direttamente gli argomenti li recupero dalla tabella principale
@@ -889,6 +975,8 @@ function TOOL.CreateParetina(nEdgeId, tbInfo, dPairAngCorr)
local dTh = tbInfo.dTh and tbInfo.dTh or EgtGetInfo(tbInfo.nId, 'Th','d')
local dThPrev = EgtGetInfo(tbInfo.nPrevId, 'Th','d') or 0
local dThNext = EgtGetInfo(tbInfo.nNextId, 'Th','d') or 0
local nJunctionWithPrev = CalcPrevJunction( tbInfo, tbInfo.nPrevId)
local nJunctionWithNext = CalcNextJunction( tbInfo, tbInfo.nNextId)
-- calcolo l'angolo di sformo con il pezzo precedente
local dXOffset = 0
@@ -899,23 +987,19 @@ function TOOL.CreateParetina(nEdgeId, tbInfo, dPairAngCorr)
if tbInfo.nPrevId~= GDB_ID.NULL then bSameSide = dPairAng * dPairAngPrev > 0 end
if bSameSide then
local dOffset = 0
if tbInfo.nJunctionType == 3 then
if nJunctionWithPrev == JUNC.Angled then
local dSideAngDx, _, dBeta_DX = CalcDraftAngle( vtDirPrev, vtDirCurr, dPairAngPrev, dPairAng, PrevAng)
--tbInfo.dAngBR = 180 - dBeta_DX
tbInfo.dAngBR = dBeta_DX
if tbInfo.bOnLoop then dSideAngDx = dSideAngDx * (-1) end
if PrevAng < 0 then dSideAngDx = dSideAngDx * (-1) end
tbInfo.dSideAngR = dSideAngDx
if not tbInfo.bOnLoop then
dLenPrev, dLen, _, dOffset = ManageJunction(PrevAng,dThPrev, dTh,tbInfo.nJunctionType, dLenPrev, dLen, tbInfo.bOnLoop)
--if tbInfo.nIn then dOffset = - dOffset end
dLenPrev, dLen, _, dOffset = ManageJunction(PrevAng,dThPrev, dTh,nJunctionWithPrev, dLenPrev, dLen, tbInfo.bOnLoop)
if tbInfo.nPairMode == 2 then dXOffset = dXOffset + dOffset end
end
else
-- se ho una giunzione a T allora devo aggiustare la lunghezza dei pezzi sia che la faccia sia On, sia che sia Off
dLenPrev, dLen, _, dOffset = ManageJunction(PrevAng,dThPrev, dTh,tbInfo.nJunctionType, dLenPrev, dLen, tbInfo.bOnLoop)
-- se sono su un inloop allora cambio il verso dell'offset
--if tbInfo.nIn then dOffset = - dOffset end
dLenPrev, dLen, _, dOffset = ManageJunction(PrevAng,dThPrev, dTh,nJunctionWithPrev, dLenPrev, dLen, tbInfo.bOnLoop)
-- setto il sideang da giunzione a T
local dSideAngDx = 90 - math.abs(PrevAng)
if tbInfo.bOnLoop then dSideAngDx = dSideAngDx * (-1) end
@@ -925,7 +1009,7 @@ function TOOL.CreateParetina(nEdgeId, tbInfo, dPairAngCorr)
end
else
-- setto il sideAng da giunzione a T (che va bene anche se la giunzione è angolata ma senza pezzo precedente)
local dSideAng = PrevAng < 0 and (90 + PrevAng) or 90-PrevAng
local dSideAng = PrevAng > 0 and (PrevAng - 90) or (90 + PrevAng)
if tbInfo.bOnLoop then dSideAng = dSideAng * (-1) end
tbInfo.dSideAngR = dSideAng
tbInfo.dAngBR = 90
@@ -933,7 +1017,8 @@ function TOOL.CreateParetina(nEdgeId, tbInfo, dPairAngCorr)
if not tbInfo.bOnLoop then
local dOffset = dTh * tan( 90 - PrevAng)
dLen = dLen + dOffset
if tbInfo.nPairMode == 2 then dXOffset = dXOffset + dOffset end
-- modifiche alla lunghezza allo start si traducono in offset di segno opposto
if tbInfo.nPairMode == 2 then dXOffset = dXOffset - dOffset end
end
end
-- -- calcolo l'angolo di sformo con il pezzo successivo
@@ -942,20 +1027,19 @@ function TOOL.CreateParetina(nEdgeId, tbInfo, dPairAngCorr)
if tbInfo.nNextId~= GDB_ID.NULL then bSameSide = dPairAng * dPairAngNext > 0 end
if bSameSide then
local dOffset = 0
if tbInfo.nJunctionType == 3 then
if nJunctionWithNext == JUNC.Angled then
local dSideAngSx, dBeta_SX, _ = CalcDraftAngle( vtDirCurr, vtDirNext, dPairAng, dPairAngNext, NextAng)
-- tbInfo.dAngBL = 180 - dBeta_SX
tbInfo.dAngBL = dBeta_SX
if tbInfo.bOnLoop then dSideAngSx = dSideAngSx * (-1) end
if NextAng < 0 then dSideAngSx = dSideAngSx * (-1) end
tbInfo.dSideAngL = dSideAngSx
if not tbInfo.bOnLoop then
dLen, dLenNext, dOffset, _ = ManageJunction(NextAng, dTh, dThNext, tbInfo.nJunctionType, dLen, dLenNext, tbInfo.bOnLoop)
dLen, dLenNext, dOffset, _ = ManageJunction(NextAng, dTh, dThNext, nJunctionWithNext, dLen, dLenNext, tbInfo.bOnLoop)
if tbInfo.nPairMode == 1 then dXOffset = dXOffset + dOffset end
end
else
-- se ho una giunzione a T allora devo aggiustare la lunghezza dei pezzi sia che la faccia sia On, sia che sia Off
dLen, dLenNext, dOffset, _ = ManageJunction(NextAng, dTh, dThNext, tbInfo.nJunctionType, dLen, dLenNext, tbInfo.bOnLoop)
dLen, dLenNext, dOffset, _ = ManageJunction(NextAng, dTh, dThNext, nJunctionWithNext, dLen, dLenNext, tbInfo.bOnLoop)
-- setto il sideang da giunzione a T
local dSideAngSx = 90 - math.abs(NextAng)
if tbInfo.bOnLoop then dSideAngSx = dSideAngSx * (-1) end
@@ -965,7 +1049,7 @@ function TOOL.CreateParetina(nEdgeId, tbInfo, dPairAngCorr)
end
else
-- setto il sideAng da giunzione a T (che va bene anche se la giunzione è angolata ma senza pezzo successivo)
local dSideAng = NextAng < 0 and (90 + NextAng) or 90-NextAng
local dSideAng = NextAng > 0 and (NextAng - 90) or (90 + NextAng)
if tbInfo.bOnLoop then dSideAng = dSideAng * (-1) end
tbInfo.dSideAngL = dSideAng
tbInfo.dAngBL = 90
@@ -973,6 +1057,7 @@ function TOOL.CreateParetina(nEdgeId, tbInfo, dPairAngCorr)
if not tbInfo.bOnLoop then
local dOffset = dTh * tan( 90 - NextAng)
dLen = dLen + dOffset
-- modifiche alla lunghezza all'end si traducono in offset dello stesso segno
if tbInfo.nPairMode == 1 then dXOffset = dXOffset + dOffset end
end
end