diff --git a/TemplateTool.lua b/TemplateTool.lua index 94e3911..21ab79a 100644 --- a/TemplateTool.lua +++ b/TemplateTool.lua @@ -79,8 +79,8 @@ end local function FillInfoTable() if TOOL.nId then TOOL.tbInfo.nId = TOOL.nId end if TOOL.nEdgeId then TOOL.tbInfo.nEdgeId = TOOL.nEdgeId end - if TOOL.nLayLoopParent and TOOL.nLayLoopParent ~= GDB_ID.NULL then TOOL.tbInfo.nLayLoopParent = TOOL.nLayLoopParent end if (not TOOL.tbInfo.nLayLoopParent or TOOL.tbInfo.nLayLoopParent == GDB_ID.NULL) and TOOL.nEdgeId and TOOL.nEdgeId ~= GDB_ID.NULL then EgtGetParent( TOOL.nEdgeId) end + TOOL.nLayLoopParent = TOOL.tbInfo.nLayLoopParent if TOOL.nParent then TOOL.tbInfo.nParent = TOOL.nParent end if (not TOOL.tbInfo.nParent or TOOL.tbInfo.nParent == GDB_ID.NULL) and TOOL.nEdgeId and TOOL.nEdgeId ~= GDB_ID.NULL then EgtGetParent(EgtGetParent( TOOL.nEdgeId)) end if TOOL.nPrevId then TOOL.tbInfo.nPrevId = TOOL.nPrevId end @@ -149,6 +149,8 @@ function TOOL.WriteDataToChildPart(tbInfo) if tbInfo.nJunctionType then EgtSetInfo(tbInfo.nId, 'JunctionType', tbInfo.nJunctionType) end if tbInfo.bOutLoop ~= nil then EgtSetInfo(tbInfo.nId, "FromOutLoop", tbInfo.bOutLoop) end if tbInfo.nIn then EgtSetInfo(tbInfo.nId, "nInLoop", tbInfo.nIn) end + if tbInfo.nPrevId then EgtSetInfo(tbInfo.nId, "Prev", EgtGetName(tbInfo.nPrevId)) end + if tbInfo.nNextId then EgtSetInfo(tbInfo.nId, "Next", EgtGetName(tbInfo.nNextId)) end end -- CREAZIONE dei Layer di un singolo Part @@ -412,8 +414,8 @@ function TOOL.CreateReference( IdPart, sNameLayer,sNameEdge, nIn, dVar, sDir, sP IdEnt = EgtGetFirstNameInGroup(nLay, sNameEdge) end if not IdEnt then - CMP.ERR=6 - CMP.MSG= CMP.MSG..' Non esiste il lato '..sNameEdge..' nel layer '..sNameLayer..' del part '..sNamePart + TOOL.ERR=6 + TOOL.MSG= TOOL.MSG..' Non esiste il lato '..sNameEdge..' nel layer '..sNameLayer..' del part '..sNamePart return end -- creo la copia dello spigolo come riferimento @@ -768,7 +770,6 @@ function TOOL.CreateCircularHole(nPart, ptCenter, dDiam) end ---function TOOL.CreateParetina(i, tbIdLoopTC, tbInfo, dPairAngCorr) function TOOL.CreateParetina(nEdgeId, tbInfo, dPairAngCorr) local tbIdLoopTC = {} if not tbInfo then @@ -884,6 +885,129 @@ function TOOL.CreateParetina(nEdgeId, tbInfo, dPairAngCorr) tbInfo.dXOffset = dXOffset end +local function CreateSplitBottomPart(tbInfo, i, tbIdEdges, ptCenter, nPrev, nFirst) + local Pz_Bottom = GDB_ID.NULL + -- devo verificare se la paretina esiste già allora devo distruggerla e ricrearla, sennò la creo da zero + local nChildPart = EgtGetFirstNarmeInGroup(GDB_ID.ROOT, EgtGetInfo(tbInfo.nParent, "A"..tbInfo.nEdge)) + if not nChildPart then + Pz_Bottom = TOOL.CreatePartLayer('BottomA'..tostring(i)) + tbInfo.sName = EgtGetName(Pz_Bottom) + EgtSetInfo(tbInfo.nParent, "A"..tbInfo.nEdge, tbInfo.sName) + tbInfo.nPrevId = nPrev + if i < #tbIdEdges then + tbInfo.nNextId = GDB_ID.NULL + else + tbInfo.nNextId = nFirst + end + + -- setto le info per la creazione del pezzo di fondo + if i == 1 then nFirst = Pz_Bottom end + tbInfo.nId = Pz_Bottom + tbInfo.nEdge = 3 -- so già che il pezzo che creo si attaccherà al lato A3 del loop della paretina del lavandino + tbInfo.nEdgeId = tbIdEdges[i] + tbInfo.nParent = tbParent[i] + tbInfo.sDestRefOff = '0,0,-x' + tbInfo.sRefOff = '0,0,0' + tbInfo.dPairAng = 90 - TOOL.dSlopeAng + tbInfo.nJunctionType = 3 + tbInfo.bOnLoop = true + tbInfo.bInsideLoop = false -- questo mi richiederà di prendere il complementare del side ang che risulta dal calcDraftAng + tbInfo.dH = (EgtPointCurveDist( ptCenter, tbInfo.nEdgeId, GDB_RT.GLOB) - TOOL.dDiamBore) / cos(TOOL.dSlopeAng) + else + -- se esisteva già ripulisco i layer della regione e del loop ed elimino il solido + ClearPart(nChildPart) + TOOL.tbInfo.nId = nChildPart + TOOL.tbInfo.sName = EgtGetName(TOOL.tbInfo.nId) + -- recupero l'id di eventuali vicini + TOOL.tbInfo.nPrevId = EgtGetFirstNameInGroup(GDB_ID.ROOT, EgtGetInfo(TOOL.tbInfo.nId, "Prev")) or GDB_ID.NULL + TOOL.tbInfo.nNextId = EgtGetFirstNameInGroup(GDB_ID.ROOT, EgtGetInfo(TOOL.tbInfo.nId, "Next")) or GDB_ID.NULL + end + -- creo il fondo come paretina + TOOL.CreateParetina( tbPart.nEdgeId, tbPart, 90) + TOOL.CreateAdjustedPart( tbLayerBottom['OutLoop'],tbPart.dLen, tbPart.dH, tbPart.dAngBL, tbPart.dAngBR) + TOOL.CreatePart(tbLayerBottom,tbPart) + + local tbLayerBottom = TOOL.FindLayers(tbInfo.nId) + if tbPart.dSideAngL then TOOL.SetSideAng(tbLayerBottom['OutLoop'], 'A2', tbPart.dSideAngL) end + if tbPart.dSideAngR then TOOL.SetSideAng(tbLayerBottom['OutLoop'], 'A4', tbPart.dSideAngR) end + -- creo i riferimenti e salvo i parametri del part + local nPartDestId = tbParent[i] + local nIdToRef = TOOL.CreateReference( nPartDestId, 'OutLoop', 'A3', nil, tbPart.dTh, tbPart.sDestRefOff, tbInfo.sName) + local nMyRef = TOOL.CreateReference( tbInfo.nId, 'OutLoop', 'A1', nil, 0, tbPart.sRefOff) + TOOL.SetPairInfo( tbInfo.nId, nMyRef, sNamePartDest, nIdToRef, -1) + -- creo il solido e lo accoppio + if SLD then + SLD.CurrId = TOOL.tbInfo.nId + SLD.Main() + end + + if ASS then + ASS.nVeinCtx = EgtGetContext() + ASS.nPartId = TOOL.tbInfo.nId + ASS.PairSingle() + end + return Pz_Bottom +end + +function TOOL.CreateSplitBottom( tbIdEdges, dOffset) + -- raccolgo e/o ricostruisco i dati in input + if not tbIdEdges then tbIdEdges = TOOL.tbIdEdges end -- tabella che contiene gli edge da cui voglio creare il fondello + local tbParent = {} + for _, nEdgeId in pairs(tbIdEdges) do + table.insert(tbParent, EgtGetParent(EgtGetParent(nEdgeId))) + end + if not dOffset then + if TOOL.dOffset then + dOffset = TOOL.dOffset + else + dOffset = 0 + end + end + + local nAuxPart = EgtGroup(GDB_ID.ROOT) + local nAuxLay = EgtGroup(nAuxPart) + local nLoop = EgtCurveCompoByChain(nAuxLay, tbIdEdges, EgtSP(tbIdEdges[1], GDB_RT.GLOB), false) + EgtOffsetCurve(nLoop, -dOffset, GDB_OT.EXTEND) -- N.B.: qui spero che si sia mantenuto il numero di curve e di poter ancora associare le curve di offset con quelle originali e con il relativo part di origine + local ptCenter = EgtGP(nLoop, GDB_RT.GLOB) + TOOL.tbIdLoop = TOOL.ExplodeAndNameEdges( nLoop, false) + + -- creo i part con tutte le info + local nPrev = GDB_ID.NULL + local nFirst = GDB_ID.NULL + local tbInfo = TOOL.tbInfo + -- da intefaccia devo settare:----------------------------------------------- + -- - TOOL.tbIdEdges + -- - dSlopeAng + -- - dDiamBore + -- - dTh + -- - dOffset + for i = 1, #tbIdEdges do + tbInfo.dTh = TOOL.dTh + nPrev = CreateSplitBottomPart(tbInfo, i, tbIdEdges, ptCenter, nPrev, nFirst) + + -- modifico le paretine vicine se serve + local nNextId = TOOL.tbInfo.nNextId + local Prev_i = i == 1 and #tbIdEdges or (i - 1) + local Next_i = i == #tbIdEdges and 1 or (i + 1) + if TOOL.tbInfo.nPrevId and TOOL.tbInfo.nPrevId ~= GDB_ID.NULL then + FillInfoTableFromPart(TOOL.tbInfo.nPrevId) + TOOL.CreateSplitBottomPart(tbInfo, Prev_i, tbIdEdges, nil, nil, nil) -- da modificare gli input per il prev + end + if nNextId and nNextId ~= GDB_ID.NULL then + FillInfoTableFromPart(nNextId) + TOOL.CreateSplitBottomPart(tbInfo, Next_i, tbIdEdges, nil, nil, nil) -- da modificare gli input per il next\ + end + + -- pulisco la tabella con i dati + TOOL.tbInfo = {} + end + + TOOL.SaveMePlease() + + -- cancello layer ed entità che non servono più... + +end + local function ClearPart(nPartId) local tbLayer = TOOL.FindLayers(nPartId) -- svuoto i layer con gli elementi principali