-- 2024/11/22 -- Template per la creazione di un cabinet -- Intestazioni require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) EgtAddToPackagePath(EgtGetSourceDir() .. 'LuaLibs\\?.lua') require( 'EgtCompo') -- Parametri : dichiarazione e valori standard -- N.B.: le dimensioni sono comprese di spessori local CMP = {} CMP.N1 = 'Altezza alzatina' -- altezza CMP.T1 = 3 -- 0=null, 1=bool, 2=int, 3=len, 4=num, 5=string CMP.V1 = 40 CMP.N2 = 'Altezza frontalino' -- larghezza CMP.T2 = 3 CMP.V2 = 60 CMP.N3 = 'Profondità lavello' -- profondità CMP.T3 = 3 CMP.V3 = 300 CMP.N4 = 'Spessore Top' -- spessore top CMP.T4 = 3 CMP.V4 = 20 CMP.N5 = 'Spessore Bottom' -- spessore bottom CMP.T5 = 3 CMP.V5 = 10 CMP.N6 = 'Spessore Alzatine' -- spessore left CMP.T6 = 3 CMP.V6 = 30 CMP.N7 = 'Spessore Frontalini' -- spessore right CMP.T7 = 3 CMP.V7 = 5 CMP.N8 = 'Dimensione Foro' -- diametro del foro CMP.T8 = 3 CMP.V8 = 5 CMP.N9 = 'Pendenza del fondo' -- angolo di pendenza del fondo CMP.T9 = 3 CMP.V9 = 0.15 CMP.ResetView = false CMP.DrawSolid = true CMP.IsCabinet = true CMP.Npar = 9 CMP.Nome = 'TopChicken' _G.CMP = CMP CMP.ERR = 0 CMP.MSG = '' -- Aggiorno con ultimi valori salvati (se presenti) CMP.DATA = EgtGetSourceDir() .. CMP.Nome ..'.dat' LoadCompoData() -- Percorso direttorio Vein3D local sPath = "" sPath = EgtGetStringFromIni( "Vein3D", "Vein3D_Dir", "", EgtGetIniFile()) EgtOutLog(' → '..sPath) -- definzione delle variabile per le classi di paretine local dAngAlzatina = 90 local dAngFrontalino = -90 -- Carico i dati letti da file .dat local tbOrigVal={} local function OrigData() tbOrigVal.v1 = CMP.V1 tbOrigVal.v2 = CMP.V2 tbOrigVal.v3 = CMP.V3 tbOrigVal.v4 = CMP.V4 tbOrigVal.v5 = CMP.V5 tbOrigVal.v6 = CMP.V6 tbOrigVal.v7 = CMP.V7 tbOrigVal.v8 = CMP.V8 tbOrigVal.v9 = CMP.V9 end --- local sUNICode = os.date( '%y%m%d%H%M%S', os.time()).."_" -- Per disporre i pezzi in piano non sovrappposti (in assemblaggio non serve) local HorizontalOffset = 0 ------------------------------------------------------------------------------------------------------------------------- -- COSTRUZIONE RIFERIMENTI INIZIO ------------------------------------------------------------------------------------------------------------------------- local function SetReference() -- Esempio Riferimento: -- CreateReference( tbName[2], 'OutLoop', 'A2', 'R1', CMP.SL, '0,0,-x') -- SetPairInfo( tbName[2], 'R1', tbName[1], 'R1', -1, 90, 1) -- Esempio Punto per dimension: -- CreatePointReference( tbName[1], 'OutLoop', 'A1', 'R4', 0, CMP.SB, '0,0,-x') --SaveMePlease() end -- local function AddDimensions() -- local GridFr = Frame3d(ORIG(),GDB_FR.FRONT) -- --Esempio: -- -- DrawLinearDimension( tbName[1], 'R4', tbName[4], 'R2', 'SUA ALTEZZA',GridFr, Point3d(-50,0,0)) -- EgtSetGridFrame(GLOB_FRM()) end -- ------------------------------------------------------------------------------------------------------------------------- -- COSTRUZIONE RIFERIMENTI FINE ------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------- -- CREAZIONE/IMPORTAZIONE Loop INIZIO ------------------------------------------------------------------------------------------------------------------------- -- Importa un contorno chiuso da file nge function ImportLoop( PartId, tbLayer, sNameFileNGE) local OutLayer = tbLayer['OutLoop'] if not EgtInsertFile( sNameFileNGE) then EgtOutLog(' IMPORTAZIONE FALLITA: '..sNameFileNGE) end -- recupero ultimo Part local LastPart = EgtGetLastPart() local FstLayerInLstPart = EgtGetFirstGroupInGroup( LastPart) local IdLoop = EgtGetFirstInGroup( FstLayerInLstPart) if not EgtRelocateGlob( IdLoop, OutLayer) then EgtOutLog(' RELOCATE FALLITA MISERAMENTE: '..tostring(IdLoop)..';'..tostring(OutLayer)) end local tbIdAllLoops = {} local tbIdLoop = TOOL.ExplodeAndNameEdges( IdLoop) table.insert(tbIdAllLoops, tbIdLoop) EgtSetInfo(tbIdLoop[1],'AF',1) EgtSetInfo(tbIdLoop[2],'AF',2) EgtSetInfo(tbIdLoop[3],'AF',2) EgtSetInfo(tbIdLoop[4],'AF',2) EgtSetInfo(tbIdLoop[5],'AF',2) EgtSetInfo(tbIdLoop[6],'AF',2) EgtSetInfo(tbIdLoop[7],'AF',1) -- controllo la presenza di eventuali inloop local IdInLoop = EgtGetFirstInGroup(FstLayerInLstPart) if IdInLoop then local InLoopLay = EgtGroup(PartId) EgtSetName(InLoopLay, 'InLoop') EgtRelocateGlob( IdInLoop, InLoopLay) local tbIdInLoop = TOOL.ExplodeAndNameEdges( IdInLoop, true) table.insert(tbIdAllLoops, tbIdInLoop) EgtSetInfo(tbIdInLoop[1],'AF',2) EgtSetInfo(tbIdInLoop[2],'AF',2) EgtSetInfo(tbIdInLoop[3],'AF',2) EgtSetInfo(tbIdInLoop[4],'AF',2) end -- cancello il part dell'importazione EgtErase(LastPart) return tbIdAllLoops end -- local function WriteDataToChildPart(nParent, nPart, nEdge, dLen, dAngDx, dAngSx, dH, dTh) if not nPart then do return end end if nParent then EgtSetInfo(nPart, 'Parent', nParent) end if nEdge then EgtSetInfo(nPart, 'ParentEdge', nEdge) end if dLen then EgtSetInfo(nPart, 'Len', dLen) end if dAngDx then EgtSetInfo(nPart, 'dAngDx', dAngDx) end if dAgnSx then EgtSetInfo(nPart, 'dAngSx', dAngSx) end if dH then EgtSetInfo(nPart, 'dH', dH) end if dTh then EgtSetInfo(nPart, 'dTh', dTh) end end -- sNamePartDest deve essere il pezzo al cui lato A1 si attacca il lato A4 del pezzo Bottom local function CreateBottomPart( tbIdLoop, sNamePartDest, nParent) -- creo il fondo del lavello local tbPart = {} local Pz_Bottom = TOOL.CreatePartLayer('Bottom', sUNICode) tbPart.sName = 'Bottom' tbPart.dTh = CMP.SB tbPart.sDestRefOff = '0,0,-x' tbPart.sRefOff = '0,0,0' tbPart.dPairAng = 90 local tbLayerBottom = TOOL.FindLayers(Pz_Bottom) local bInvert = true local bInLoop = false local tbOutLoop = TOOL.AddLoopToLayer(tbLayerBottom['OutLoop'], tbIdLoop, CMP.SWater, bInvert, bInLoop) -- il loop viene aggiunto ma nella posizione da inloop del piano cucina, non come nuovo pezzo messo nell'origine TOOL.CreatePart(tbLayerBottom,tbPart.sName,tbOutLoop,tbPart.dTh,bInLoop) -- creo il foro local ptCenter = EgtGP( EgtGetFirstInGroup(tbLayerBottom['Region']), GDB_RT.GLOB) TOOL.CreateCircularHole( Pz_Bottom, ptCenter, CMP.DiamBore) --TOOL.CreatePart(tbLayerBottom,tbPart.sName,{HoleId},tbPart.dTh,true) -- creo i riferimenti e salvo i parametri del part TOOL.CreateReference( sUNICode, sNamePartDest, 'OutLoop', 'A1', 'R1', tbPart.dTh, tbPart.sDestRefOff) TOOL.CreateReference(sUNICode, tbPart.sName, 'OutLoop', 'A4', 'R4', 0, tbPart.sRefOff) TOOL.SetPairInfo(sUNICode, tbPart.sName, 'R4', sNamePartDest, 'R1', -1, tbPart.dPairAng, 4) WriteDataToChildPart(nParent, Pz_Bottom, nEdge,tbPart.dLen,tbPart.dAngBR, tbPart.dAngBL, tbPart.dH, tbPart.dTh) end local function CreateSplitBottomPart( tbIdLoop, nParent) -- creo il fondo diviso in un numero di pezzi pari ai lati del loop passato local nLay = EgtGetParent(tbIdLoop[1]) local nLoop = EgtCurveCompoByChain(nLay, tbIdLoop, EgtSP(tbIdLoop[1], GDB_RT.GLOB), false) local ptCenter = EgtGP(nLoop, GDB_RT.GLOB) EgtErase(nLoop) local nPrev = 0 local nFirst = 0 local tbSplitBottom = {} -- creo i part con tutte le info for i = 1, #tbIdLoop do local tbPart = {} local Pz_Bottom = TOOL.CreatePartLayer('BottomA'..tostring(i), sUNICode) if i == 1 then nFirst = Pz_Bottom end tbPart.sName = 'BottomA'..tostring(i) tbPart.nId = Pz_Bottom tbPart.nEdge = i tbPart.dTh = CMP.SB EgtSetInfo(Pz_Bottom, 'dTh', CMP.SB) tbPart.sDestRefOff = '0,0,-x' tbPart.sRefOff = '0,0,0' tbPart.dPairAng = 90 - CMP.dSlopeAng EgtSetInfo(Pz_Bottom, 'PairAng', tbPart.dPairAng) tbPart.nJunctionType = 3 tbPart.dH = EgtPointCurveDist( ptCenter, tbIdLoop[i], GDB_RT.GLOB) tbPart.nPrev = nPrev if i > 1 then tbSplitBottom[nPrev].nNext = Pz_Bottom end tbSplitBottom[Pz_Bottom] = tbPart nPrev = Pz_Bottom end tbSplitBottom[nPrev].nNext = nFirst tbSplitBottom[nFirst].nPrev = nPrev -- scorro i part e costruisco effettivamente i pezzi in funzione del precedente e del successivo for nPart, tbPart in pairs(tbSplitBottom) do local tbLayerBottom = TOOL.FindLayers(nPart) local bInLoop = false TOOL.CreateParetina( tbPart.nEdge, tbIdLoop, tbPart) local tbPartLoop = TOOL.CreateAdjustedPart( tbLayerBottom['OutLoop'],tbPart.dLen, tbPart.dH, tbPart.dAngBL, tbPart.dAngBR) TOOL.CreatePart(tbLayerBottom,tbPart.sName,tbPartLoop,tbPart.dTh,bInLoop) TOOL.SetMachiningInfo(tbLayerBottom['OutLoop'], false) 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 sNamePartDest = 'InPartA'..tostring(tbPart.nEdge) TOOL.CreateReference( sUNICode, sNamePartDest, 'OutLoop', 'A1', 'R1', tbPart.dTh, tbPart.sDestRefOff) TOOL.CreateReference(sUNICode, tbPart.sName, 'OutLoop', 'A3', 'R3', 0, tbPart.sRefOff) TOOL.SetPairInfo(sUNICode, tbPart.sName, 'R3', sNamePartDest, 'R1', -1, tbPart.dPairAng, 4) WriteDataToChildPart(nParent, nPart, nEdge,tbPart.dLen,tbPart.dAngBR, tbPart.dAngBL, tbPart.dH, tbPart.dTh) end return tbSplitBottom end -- Confronto i dati del file.dat con quelli letti da programma local function IsDataChanged() local bOk = false if not tbOrigVal.v1 then return true end if math.abs(CMP.V1 - tbOrigVal.v1) > 0.5 then bOk = bOk or true end if math.abs(CMP.V2 - tbOrigVal.v2) > 0.5 then bOk = bOk or true end if math.abs(CMP.V3 - tbOrigVal.v3) > 0.5 then bOk = bOk or true end if math.abs(CMP.V4 - tbOrigVal.v4) > 0.5 then bOk = bOk or true end if math.abs(CMP.V5 - tbOrigVal.v5) > 0.5 then bOk = bOk or true end if math.abs(CMP.V6 - tbOrigVal.v6) > 0.5 then bOk = bOk or true end if math.abs(CMP.V7 - tbOrigVal.v7) > 0.5 then bOk = bOk or true end if math.abs(CMP.V8 - tbOrigVal.v8) > 0.5 then bOk = bOk or true end if math.abs(CMP.V9 - tbOrigVal.v9) > 0.005 then bOk = bOk or true end return bOk end -- EgtAddToPackagePath(sPath..'TemplateTool.lua') -- require('TemplateTool') local TOOL = dofile(sPath..'TemplateTool.lua') function CMP_Draw(bPreview) local bRedraw = IsDataChanged() if bRedraw or not CMP.DrawSolid then -- pulisco il file e leggo i dati EgtNewFile() HorizontalOffset = 0 CMP.HSplash = CMP.V1 -- altezza alzatina CMP.HWater = CMP.V2 -- altezza frotalino CMP.DSink = CMP.V3 -- profondità lavello CMP.ST = CMP.V4 -- spessore top CMP.SB = CMP.V5 -- spessore bottom CMP.SSplash = CMP.V6 -- spessore alzatine CMP.SWater = CMP.V7 -- spessore frontalini CMP.DiamBore = CMP.V8 -- spessore back CMP.dSlopeAng = CMP.V9 -- angolo di pendenza -- PIANO POLLO local Pz_Top = TOOL.CreatePartLayer( 'TopChicken', sUNICode) -- Creo il contorno esterno (id degli edge esterni) local tbLoopsTC = ImportLoop( Pz_Top, TOOL.FindLayers( Pz_Top), sPath .. 'TopChicken.nge') local tbIdLoopTC = tbLoopsTC[1] local tbIdInLoopTC = tbLoopsTC[2] -- Creo il pezzo dato il contorno local dTh_TC = CMP.ST local tbTCLayer = TOOL.FindLayers( Pz_Top) TOOL.CreatePart( tbTCLayer, 'TopChicken', tbIdLoopTC, dTh_TC, false) if tbTCLayer['InLoop'] then TOOL.CreatePart( tbTCLayer, 'TopChicken', tbIdInLoopTC, dTh_TC, true) end --INIZIO CREAZIONE PARETINE dell'OutLoop -- tabella che contiene le tabelle con le info dei vari part local tbPartsInfo = {} local dThCurr = 20 local dHCurr = 100 local nPrev = 0 local nFirst = 0 for i=1, #tbIdLoopTC do local tbInfo = {} tbInfo.nEdge = i tbInfo.nPrev = nPrev local sNamePz = 'PartA'.. tostring(i) tbInfo.sName = sUNICode..sNamePz local Pz_A = TOOL.CreatePartLayer(sNamePz, sUNICode) if nPrev ~= 0 then tbPartsInfo[nPrev].nNext = Pz_A end if i == 1 then nFirst = Pz_A end tbInfo.nId = Pz_A tbInfo.sName = sNamePz local nType = EgtGetInfo(tbIdLoopTC[i], 'AF', 'i') or 0 local dPairAng = 0 if nType == 1 then dPairAng = dAngAlzatina EgtSetInfo(Pz_A, 'dTh', CMP.SSplash) EgtSetInfo(Pz_A, 'dH', CMP.HSplash) elseif nType == 2 then dPairAng = dAngFrontalino EgtSetInfo(Pz_A, 'dTh', CMP.SWater) EgtSetInfo(Pz_A, 'dH', CMP.HWater) end tbInfo.nType = nType EgtSetInfo(Pz_A, 'PairAng', dPairAng) nPrev = Pz_A tbPartsInfo[tbInfo.nId] = tbInfo end tbPartsInfo[nFirst].nPrev = nPrev tbPartsInfo[nPrev].nNext = nFirst -- aggiungo le paretine dell'InLoop nPrev = 0 nFirst = 0 for i=1, #tbIdInLoopTC do local tbInfo = {} tbInfo.nEdge = i tbInfo.nPrev = nPrev local sNamePz = 'InPartA'.. tostring(i) tbInfo.sName = sUNICode..sNamePz local Pz_A = TOOL.CreatePartLayer(sNamePz, sUNICode) if nPrev ~= 0 then tbPartsInfo[nPrev].nNext = Pz_A end if i == 1 then nFirst = Pz_A end tbInfo.nId = Pz_A tbInfo.sName = sNamePz local nType = EgtGetInfo(tbIdInLoopTC[i], 'AF', 'i') or 0 local dPairAng = 0 if nType == 1 then dPairAng = dAngAlzatina elseif nType == 2 then dPairAng = dAngFrontalino end tbInfo.nType = nType EgtSetInfo(Pz_A, 'PairAng', dPairAng) EgtSetInfo(Pz_A, 'dTh', CMP.SWater) EgtSetInfo(Pz_A, 'dH', CMP.DSink) nPrev = Pz_A tbInfo.bInLoop = true tbPartsInfo[tbInfo.nId] = tbInfo end tbPartsInfo[nFirst].nPrev = nPrev tbPartsInfo[nPrev].nNext = nFirst --local bOnLoop = false -- bool che indica se la faccia buona del part sta sull'edge del piano cucina o no --local nJunctionType = 1 -- tipo di giunzione: 1 trim start, 2 trim end, 3 giunzione angolata for nPart, tbInfo in pairs( tbPartsInfo) do local nType = tbInfo.nType local dH = EgtGetInfo(nPart, 'dH', 'd') tbInfo.dH = dH local dTh = EgtGetInfo(nPart, 'dTh', 'd') local dPairAng = EgtGetInfo(nPart, 'PairAng', 'd') if nType == 1 then ----- caratteristiche alzatina tbInfo.dPairAng = dPairAng tbInfo.dSideAngT = dPairAng - 90 tbInfo.dTh = dTh tbInfo.dYOffset = dTh * tan(tbInfo.dSideAngT) --nJunctionType = 2 -- trim end --nJunctionType = 1 -- trim start tbInfo.nJunctionType = 1 -- angle junction tbInfo.bOnLoop = false ----- caratteristiche alzatina elseif nType == 2 then ----- caratteristiche frontalino tbInfo.dPairAng = dPairAng tbInfo.dSideAngT = -( -dPairAng - 90) tbInfo.dTh = dTh tbInfo.dYOffset = dTh * tan(tbInfo.dSideAngT) tbInfo.nJunctionType = 3 -- angle junction tbInfo.bOnLoop = true ----- caratteristiche forntalino end if not tbInfo.bInLoop then TOOL.CreateParetina( tbInfo.nEdge, tbIdLoopTC, tbInfo) else TOOL.CreateParetina( tbInfo.nEdge, tbIdInLoopTC, tbInfo) end -- setto l'offset dei riferimenti if nType == 1 then -- SPLASHTOP tbInfo.sDestRefOff = '0,0,0' tbInfo.sRefOff = tostring(tbInfo.dXOffset)..','..tostring(tbInfo.dYOffset)..',-x' elseif nType == 2 then -- WATERFALL tbInfo.sDestRefOff = '0,0,-x' tbInfo.sRefOff = '0,'..tostring(tbInfo.dYOffset)..',0' end end -- creo tutte le paretine for nPart, tbPart in pairs( tbPartsInfo) do EgtOutLog(tostring(nPart)) local nNameChar = tbPart.bInLoop and 8 or 6 local nEdge = string.sub(tbPart.sName, nNameChar) local tbLayer = TOOL.FindLayers(nPart) local tbIdLoop = TOOL.CreateAdjustedPart( tbLayer['OutLoop'],tbPart.dLen, tbPart.dH, tbPart.dAngBL, tbPart.dAngBR) TOOL.CreatePart(tbLayer,tbPart.sName,tbIdLoop,tbPart.dTh,false) if not tbPart.bInLoop then TOOL.CreateReference( sUNICode, 'TopChicken', 'OutLoop', 'A'..tostring(nEdge), 'R'..tostring(nEdge), dTh_TC, tbPart.sDestRefOff) TOOL.CreateReference(sUNICode, tbPart.sName, 'OutLoop', 'A3', 'R3', tbPart.dTh, tbPart.sRefOff) TOOL.SetPairInfo(sUNICode, tbPart.sName, 'R3', 'TopChicken', 'R'..tostring(nEdge), -1, tbPart.dPairAng, 2) else TOOL.CreateReference( sUNICode, 'TopChicken', 'InLoop', 'A'..tostring(nEdge), 'R'..tostring(nEdge+#tbIdLoopTC), dTh_TC, tbPart.sDestRefOff) TOOL.CreateReference(sUNICode, tbPart.sName, 'OutLoop', 'A3', 'R3', tbPart.dTh, tbPart.sRefOff) TOOL.SetPairInfo(sUNICode, tbPart.sName, 'R3', 'TopChicken', 'R'..tostring(nEdge+#tbIdLoopTC), -1, tbPart.dPairAng, 2) end if tbPart.dSideAngL then TOOL.SetSideAng(tbLayer['OutLoop'], 'A2', tbPart.dSideAngL) end if tbPart.dSideAngR then TOOL.SetSideAng(tbLayer['OutLoop'], 'A4', tbPart.dSideAngR) end if tbPart.dSideAngT then TOOL.SetSideAng(tbLayer['OutLoop'], 'A3', tbPart.dSideAngT) end WriteDataToChildPart(Pz_Top, nPart, nEdge,tbPart.dLen,tbPart.dAngBR, tbPart.dAngBL, tbPart.dH, tbPart.dTh) end -- -- creo il fondo CreateBottomPart( tbIdInLoopTC, 'InPartA4') --CreateSplitBottomPart( tbIdInLoopTC, Pz_Top) --TOOL.SaveMePlease() TOOL.CreateDimensionLayer() SetReference() if CMP.DrawSolid then loadfile(sPath ..'\\'.. "CreateSOLID_FromPartsInPark.lua")({AutoRun=true}) TOOL.RelocateLabels() loadfile(sPath ..'\\'.. "OperationOnSolid.lua")({AutoRun=true, nVeinCtx=EgtGetContext()}) AddDimensions() end -- Se non ci sono errori salvo i dati if CMP.ERR == 0 then -- scrivo i parametri nelle info del pezzo !! DA FARE !! -- WriteCompoDataToPart( Pz, CMP.Nome, CMP.Npar) -- salvo i parametri come nuovo default SaveCompoData(CMP.Npar) OrigData() end --EgtSaveFile(EgtGetStringFromIni( "Vein3D", "Vein3D_Dir", "", EgtGetIniFile()) ..'\\'.. "FOO.nge") --EgtSaveFile("D:\\Temp\\marmo\\Vein3D\\piano_assemblato.nge") end end --CMP_Draw() _G.CMP_Draw = CMP_Draw