Files
StoneSolidGen/TopChicken.lua
T
Daniele Bariletti f948be4c49 - aggiunta per corretta importazione in parcheggio
- pulizia codice
- creazione funzione per aggiunta fori nei pezzi.
2024-12-17 10:47:59 +01:00

411 lines
16 KiB
Lua

-- 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.ResetView = false
CMP.DrawSolid = true
CMP.IsCabinet = true
CMP.Npar = 8
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
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)
EgtSetInfo(nPart, 'Parent', nParent)
EgtSetInfo(nPart, 'ParentEdge', nEdge)
EgtSetInfo(nPart, 'Len', dLen)
EgtSetInfo(nPart, 'dAngDx', dAngDx)
EgtSetInfo(nPart, 'dAngSx', dAngSx)
EgtSetInfo(nPart, 'dH', dH)
EgtSetInfo(nPart, 'dTh', dTh)
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
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
-- 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
-- TOOL.SaveMePlease()
-- creo il fondo del lavello
local tbPart = {}
local Pz_Bottom = TOOL.CreatePartLayer('Bottom', sUNICode)
tbPart.sName = 'Bottom'
tbPart.dLen = EgtCurveLength(tbIdInLoopTC[1]) + CMP.SWater * 2
tbPart.dH = EgtCurveLength(tbIdInLoopTC[2]) + CMP.SWater * 2
tbPart.dAngBL = 90
tbPart.dAngBR = 90
tbPart.dTh = CMP.SB
local dXOffset = - CMP.SWater * tan(45) -- side ang del InPart4 sul lato A1
tbPart.sDestRefOff = tostring(dXOffset)..',0,-x'
tbPart.sRefOff = '0,0,0'
tbPart.dPairAng = 90
local tbLayerBottom = TOOL.FindLayers(Pz_Bottom)
local tbIdLoop = TOOL.CreateAdjustedPart( tbLayerBottom['OutLoop'],tbPart.dLen, tbPart.dH, tbPart.dAngBL, tbPart.dAngBR)
TOOL.CreatePart(tbLayerBottom,tbPart.sName,tbIdLoop,tbPart.dTh,false)
-- 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, 'InPartA4', 'OutLoop', 'A1', 'R1', tbPart.dTh, tbPart.sDestRefOff)
TOOL.CreateReference(sUNICode, tbPart.sName, 'OutLoop', 'A4', 'R4', 0, tbPart.sRefOff)
TOOL.SetPairInfo(sUNICode, tbPart.sName, 'R4', 'InPartA4', 'R1', -1, tbPart.dPairAng, 2)
WriteDataToChildPart(Pz_Top, Pz_Bottom, nEdge,tbPart.dLen,tbPart.dAngBR, tbPart.dAngBL, tbPart.dH, tbPart.dTh)
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