Files
StoneSolidGen/Cabinet.lua
T
Daniele Bariletti b307f76f63 - impostato il check per la rigenerazione della scena solo se i dati sono cambiati
- aggiunti controlli
- accoprato il codice in funzioni
- aggiunti commenti.
2024-12-02 10:41:28 +01:00

562 lines
21 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' -- altezza
CMP.T1 = 3 -- 0=null, 1=bool, 2=int, 3=len, 4=num, 5=string
CMP.V1 = 400
CMP.N2 = 'Larghezza' -- larghezza
CMP.T2 = 3
CMP.V2 = 600
CMP.N3 = 'Profondità' -- profondità
CMP.T3 = 3
CMP.V3 = 300
CMP.N4 = 'Spessore Top' -- spessore top
CMP.T4 = 3
CMP.V4 = 6
CMP.N5 = 'Spessore Bottom' -- spessore bottom
CMP.T5 = 3
CMP.V5 = 8
CMP.N6 = 'Spessore Left' -- spessore left
CMP.T6 = 3
CMP.V6 = 8
CMP.N7 = 'Spessore Right' -- spessore right
CMP.T7 = 3
CMP.V7 = 65
CMP.N8 = 'Spessore Back' -- spessore back
CMP.T8 = 3
CMP.V8 = 7
CMP.ResetView = false
CMP.DrawSolid = true
CMP.Npar = 8
CMP.Nome = 'Cabinet'
_G.CMP = CMP
CMP.ERR = 0
CMP.MSG = ''
-- Aggiorno con ultimi valori salvati (se presenti)
CMP.DATA = EgtGetSourceDir() .. CMP.Nome ..'.dat'
LoadCompoData()
-- 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 tbName = {'Bottom', 'Left', 'Right', 'Top', 'Back'}
local sUNICode = os.date( '%y%m%d%H%M%S', os.time()).."_"
-- CREAZIONE Layer di un singolo Part
local function CreatePartLayer(PartName)
-- Pezzo e Layer
local Pz = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC) -- pezzo
EgtSetName( Pz, sUNICode..PartName)
local LOut = EgtGroup(Pz,GDB_RT.LOC) -- layer della figura principale
EgtSetName(LOut,'OutLoop')
local LIn = EgtGroup(Pz,GDB_RT.LOC) -- layer della figura principale
EgtSetName(LIn,'InLoop')
local LReg = EgtGroup(Pz,GDB_RT.LOC) -- layer regione
EgtSetName(LReg,'Region')
local LRef = EgtGroup(Pz,GDB_RT.LOC) -- layer riferimenti
EgtSetName(LRef,'Ref')
EgtSetStatus( LRef, GDB_ST.OFF)
local LLabel= EgtGroup(Pz,GDB_RT.LOC) -- layer etichette
EgtSetName(LLabel,'Labels')
local LAux= EgtGroup(Pz,GDB_RT.LOC) -- layer etichette
EgtSetName(LAux,'Aux')
end
--
-- RESTITUISCE una tabella con gli Id dei layer del part, altrimenti nil
local function FindLayers( IdPart)
if not EgtIsPart( IdPart) then
CMP.ERR = 1
CMP.MSG = CMP.MSG.." In FindLayers 'IdPart' non è un Part"
return nil
end
local tbLayer = {}
tbLayer['OutLoop'] = EgtGetFirstNameInGroup(IdPart, 'OutLoop')
tbLayer['InLoop'] = EgtGetFirstNameInGroup(IdPart, 'InLoop')
tbLayer['Region'] = EgtGetFirstNameInGroup(IdPart, 'Region')
tbLayer['Ref'] = EgtGetFirstNameInGroup(IdPart, 'Ref')
tbLayer['Labels'] = EgtGetFirstNameInGroup(IdPart, 'Labels')
tbLayer['Aux'] = EgtGetFirstNameInGroup(IdPart, 'Aux')
return tbLayer
end
--
-- CREAZIONE Layers per ogni Parts indicato in tabella 'tbName' e Layer Dimensions
local function CreateLayers()
for i=1, 5 do
-- Pezzo e Layer
CreatePartLayer(tbName[i])
end
local Pz = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC) -- layer dimensioni e etichette
EgtSetName( Pz, 'Dimensions')
end
--
-- ASSEGNO Info per conoscere le direzioni dei lati
local function SetMachiningInfo(Layer, bInLoop)
-- if not bInLoop then return end
if EgtIsLayer( Layer) then
local LayerName = EgtGetName( Layer)
-- verifico che sia di tipo In o Out, altrimenti ricerco nel Part il layer
if not LayerName == 'OutLoop' or not LayerName == 'InLoop' then
Layer = EgtGetFirstInGroup( Layer)
CMP.ERR = 2
CMP.MSG = CMP.MSG.." In SetMachiningInfo il Layer non è di tipo 'OutLoop' o 'InLoop'."
end
else
CMP.ERR = 3
CMP.MSG = CMP.MSG.." In SetMachiningInfo il Layer non è di tipo 'OutLoop' o 'InLoop'."
end
local nId = EgtGetFirstInGroup(Layer)
local nPrevId = EgtGetLastInGroup(Layer)
local nNextId = EgtGetNext(nId)
local nFirstId = nId
local nEdges = EgtGetGroupObjs(Layer)
for i = 1, nEdges do
-- recupero i dati
local vtCurrS = EgtSV(nId, GDB_RT.GLOB)
local vtPrevS = EgtSV(nPrevId, GDB_RT.GLOB)
local vtNextS = EgtSV(nNextId, GDB_RT.GLOB)
local vtAx = Z_AX()
if bInLoop then vtAx=-vtAx end
local NextAng = GetRotation( vtCurrS, vtNextS, vtAx)
local PrevAng = GetRotation( vtPrevS, vtCurrS, vtAx)
-- scrivo le info
EgtSetInfo(nId, 'PrevAng', PrevAng)
EgtSetInfo(nId, 'NextAng', NextAng)
-- aggiorno gli id
nPrevId = nId
nId = nNextId
nNextId = EgtGetNext(nNextId)
if nNextId == nil then
nNextId = nFirstId
end
end
end
--
-- Dato un contorno ricavo i lati nel Layer di appartenenza del contorno
-- altrimenti se Part ricavo i lati nel loop specificato (Default=OutLoop o InLoop)
local function ExplodeAndNameEdges( IdLoop, bInLoop)
local sNameLayer = ''
if bInLoop then
sNameLayer = 'InLoop'
else
sNameLayer = 'OutLoop'
end
if not IdLoop or IdLoop == -1 then end
-- Se l'Id è un Part
if EgtIsPart( IdLoop) then
local tbLayer = FindLayers( IdLoop)
if tbLayer then IdLoop = EgtGetFirstInGroup( tbLayer[sNameLayer]) end
end
-- Se l'Id è un Layer
if EgtIsLayer( IdLoop) then
local LayerName = EgtGetName( IdLoop)
-- verifico che sia di tipo In o Out, altrimenti ricerco nel Part il layer
if LayerName == sNameLayer then
IdLoop = EgtGetFirstInGroup( IdLoop)
else
local tbLayer = FindLayers( EgtGetParent(IdLoop))
if tbLayer then IdLoop = EgtGetFirstInGroup( tbLayer[sNameLayer]) end
end
end
local nLay = EgtGetParent(IdLoop)
local nEdge, nTotEdges = EgtExplodeCurveCompo(IdLoop)
local nCount = 1
while nEdge do
local tbName = EgtNumToString(nCount)
EgtSetName( nEdge, "A"..tbName)
nCount = nCount + 1
nEdge = EgtGetNext(nEdge)
end
-- Ricavo info direzioni
SetMachiningInfo(nLay,bInLoop)
end
--
-- Per disporre i pezzi in piano non sovrappposti (in assemblaggio non serve)
local HorizontalOffset = 0
-- CREAZIONE di un solido, o della sua buca
local function CreatePart_0(IdPart, sName, ptDiagStart, ptDiagEnd, dTh, dOffset, bInLoop)
-- recupero il layer del contorno
local sNameLayer = ''
if bInLoop then
sNameLayer = 'InLoop'
if not ptDiagStart then
ptDiagStart = {1,1,0}
CMP.ERR = 4
CMP.MSG = CMP.MSG.." Manca la definizione del punto iniziale per l'InLoop, di default (1,1,0)."
end
else
sNameLayer = 'OutLoop'
ptDiagStart = ORIG()
end
-- Recupero gli Id dei Layer (che sono vuoti)
local tbLayer = FindLayers( IdPart)
-- Nel Layer OutLoop o InLoop definisco il contorno RETTANGOLO
EgtOutLog(sNameLayer..' '..tostring(tbLayer[sNameLayer]))
local IdLoop = EgtRectangle2P(tbLayer[sNameLayer],ptDiagStart,ptDiagEnd,GDB_RT.GLOB)
-- Nel Layer Region definisco la regione piana
local IdReg = EgtSurfFlatRegion(tbLayer['Region'],IdLoop)
-- Se InLoop allora faccio la sottrazione con la regione OutRegion
if sNameLayer == 'InLoop' then
local IdOutRegion = EgtGetPrev(IdReg)
if not EgtSurfFrSubtract( IdOutRegion,IdReg) then
CMP.ERR = 5
CMP.MSG = CMP.MSG.." Sottrazione tra superficie 'OutLoop' "..tostring(IdOutRegion).." e 'InLoop' "..tostring(IdReg).." non riuscita."
end
--EgtErase(IdReg) --debug
end
if bInLoop then EgtInvertCurve(IdLoop) end
-- Ricavo i lati da lavorare
ExplodeAndNameEdges( IdLoop)
-- Se sono InLoop non devo settare
if bInLoop then return end
-- definisco spessore pezzo
EgtSetInfo(IdPart, 'Th', dTh)
-- INFO NECESSARIA
EgtSetInfo(IdPart, 'Paired',tostring(IdPart))
-- inserisco le etichette del pezzo
local ptTop = Point3d(ptDiagEnd)/2
local ptBottom = Point3d( ptTop:getX(), -ptTop:getY(), dTh)
EgtTextAdv(tbLayer['Labels'], ptTop,0,sName, '', 10, '', 15,1.5,0,GDB_TI.MC)
if CMP.DrawSolid then
EgtSetGridFrame(Frame3d(ORIG(),GDB_FR.BOTTOM))
EgtTextAdv(tbLayer['Labels'], ptBottom,0,sName, '', 10, '', 15,1.5,0,GDB_TI.MC, GDB_RT.GRID)
EgtSetGridFrame(Frame3d(ORIG(),GDB_FR.TOP))
end
-- dispongo il pezzo in piano
local vtMove = Vector3d({dOffset,0,0})
--EgtMove(IdPart,vtMove, GDB_RT.GLOB)
HorizontalOffset = HorizontalOffset + Point3d(ptDiagEnd):getX()
end
--
local function CreatePart(tbLayer, sName, IdEntCrv, dTh, dOffset, bInLoop)
-- recupero il layer del contorno
local sNameLayer = ''
if bInLoop then
sNameLayer = 'InLoop'
else
sNameLayer = 'OutLoop'
end
-- recupero l'Id del part
local IdPart = EgtGetParent( tbLayer[sNameLayer])
-- Nel Layer OutLoop o InLoop definisco il contorno RETTANGOLO
EgtOutLog(sNameLayer..' '..tostring(tbLayer[sNameLayer]))
-- Copio nel layer OutLoop/InLoop il contorno
local IdLoop = EgtCopy( IdEntCrv, tbLayer[sNameLayer])
EgtErase(IdEntCrv)
-- Nel Layer Region definisco la regione piana
local IdReg = EgtSurfFlatRegion(tbLayer['Region'],IdLoop)
-- Se InLoop allora faccio la sottrazione con la regione OutRegion
if sNameLayer == 'InLoop' then
local IdOutRegion = EgtGetPrev(IdReg)
if not EgtSurfFrSubtract( IdOutRegion,IdReg) then
CMP.ERR = 5
CMP.MSG = CMP.MSG.." Sottrazione tra superficie 'OutLoop' "..tostring(IdOutRegion).." e 'InLoop' "..tostring(IdReg).." non riuscita."
end
EgtErase(IdReg)
end
if bInLoop then EgtInvertCurve(IdLoop) end
-- Ricavo i lati da lavorare
ExplodeAndNameEdges( IdLoop)
-- Se sono InLoop non devo settare
if bInLoop then return end
-- definisco spessore pezzo
EgtSetInfo(IdPart, 'Th', dTh)
-- INFO NECESSARIA
EgtSetInfo(IdPart, 'Paired',tostring(IdPart))
-- inserisco le etichette del pezzo nel centro della superofocie
local ptTop = EgtCP( IdReg, GDB_RT.GLOB)
local ptBottom = Point3d( ptTop:getX(), -ptTop:getY(), dTh)
EgtTextAdv(tbLayer['Labels'], ptTop,0,sName, '', 10, '', 15,1.5,0,GDB_TI.MC)
if CMP.DrawSolid then
EgtSetGridFrame(Frame3d(ORIG(),GDB_FR.BOTTOM))
EgtTextAdv(tbLayer['Labels'], ptBottom,0,sName, '', 10, '', 15,1.5,0,GDB_TI.MC, GDB_RT.GRID)
EgtSetGridFrame(Frame3d(ORIG(),GDB_FR.TOP))
end
-- dispongo il pezzo in piano
local vtMove = Vector3d({dOffset,0,0})
--EgtMove(IdPart,vtMove, GDB_RT.GLOB)
HorizontalOffset = HorizontalOffset + ptTop:getX()*2
end
--
-- Sposto l'etichetta del nome del Part nel Solido associato
local function RelocateLabels()
local nPartId = EgtGetFirstPart()
while nPartId do
local nChild = EgtGetInfo(nPartId, 'Child','i')
if nChild then
local nLaySource = EgtGetFirstNameInGroup(nPartId, 'Labels')
if nLaySource then EgtRelocateGlob( nLaySource, nChild) end
end
nPartId = EgtGetNext(nPartId)
end
end
--
-- Crea una copia dello spigolo e lo salva nel layer Ref
-- Nome del part (da tbName[1]),
-- Nome del Layer (OutLoop o InLoop),
-- Nome dello spigolo,
-- Nome della copia riferimento
-- Info per spostamento Ref in funzione di una variabile
local function CreateReference( sNamePart, sNameLayer,sNameEdge, sNameRef, dVar, sDir)
local IdPart = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode..sNamePart)
local tbLayer = FindLayers( IdPart)
--accoppiamento di left su bottom
local IdEnt = EgtGetFirstNameInGroup(tbLayer[sNameLayer], sNameEdge)
if not IdEnt then
CMP.ERR=6
CMP.MSG= CMP.MSG..' Non esiste il lato '..sNameEdge..' nel layer '..sNameLayer..' del part '..sNamePart
return
end
-- creo la copia dello spigolo come riferimento
local IdRef = EgtCopy( IdEnt, tbLayer['Ref'])
EgtSetName( IdRef, sNameRef)
if dVar and sDir then
EgtSetInfo(IdRef, 'Var', dVar)
EgtSetInfo(IdRef, 'Dir', sDir)
end
return IdRef
end
--
-- Crea una copia dello del punto dello spigolo e lo salva nel layer Ref
-- Nome del part (da tbName[1]),
-- Nome del Layer (OutLoop o InLoop),
-- Nome dello spigolo,
-- Nome della copia punto
-- Tipo di punto: 0/nil START, 1 END, 2 MID
local function CreatePointReference( sNamePart, sNameLayer,sNameEdge, sNameRef, nTypePt)
local IdPart = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode..sNamePart)
local tbLayer = FindLayers( IdPart)
--accoppiamento di left su bottom
local IdEnt = EgtGetFirstNameInGroup(tbLayer[sNameLayer], sNameEdge)
if not IdEnt then
CMP.ERR=6
CMP.MSG= CMP.MSG..' Non esiste il lato '..sNameEdge..' nel layer '..sNameLayer..' del part '..sNamePart
return
end
local pt = EgtSP(IdEnt, GDB_RT.GLOB)
if nTypePt == 1 then
pt = EgtEP(IdEnt, GDB_RT.GLOB)
elseif nTypePt == 2 then
pt = EgtMP(IdEnt, GDB_RT.GLOB)
end
local IdPtRef = EgtPoint( tbLayer['Ref'], pt, GDB_RT.GLOB)
EgtSetName(IdPtRef, sNameRef)
return IdPtRef
end
--
-- Accoppia lato a riferimento
-- Nome del pezzo da accoppiare
-- Nome del riferimento da usare
-- Nome del pezzo destinatario dell'accoppiamento
-- Nome del riferimento da usare come destinatario dell'accoppiamento
-- Concordanza del verso dei due spigoli
-- Angolo relativo tra i due pezzi: porta la normale della regione del pezzo corrente a coincidere
-- con la normale della regione del pezzo destinatario; il segno è riferito al verso del riferimento del part destinatario
-- Modalità di accoppiamento tra gli spigoli (0: start-start, 1:start-end, 2: end-start, 3: end-end, 4: mid-mid)
local function SetPairInfo( sMyNamePart, sNameMyRef, sToNamePart, sNameToRef, nPairSpin, dPairAng, nPairMode)
local nPart = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode..sMyNamePart)
EgtSetInfo(nPart, "PairMyRef", sNameMyRef)
EgtSetInfo(nPart, "PairToRef", sUNICode..sToNamePart.."_"..sNameToRef)
EgtSetInfo(nPart, "PairSpin", nPairSpin)
EgtSetInfo(nPart, "PairAng", dPairAng)
if nPairMode then EgtSetInfo(nPart, "PairMode", nPairMode) end
end
-- Disegna la quota lineare
-- Nome del part in cui trovare il primo punto di riferimento
-- Nome del punto riferimento nel part indicato sopra
-- Nome del part in cui trovare il secondo punto di riferimento
-- Nome del punto riferimento nel part indicato sopra
-- Nome/valore stringa da scrivere nella dimensione
-- Frame del piano su cui disegnare la quotatura
-- Offset etichetta rispetto al punto medio
local function DrawLineraDimension( sNamePart1, sNameRef1, sNamePart2, sNameRef2, sNameDimension, GridFrame, ptOffset)
EgtSetGridFrame(GridFrame)
local nDimLay = EgtGetFirstNameInGroup(GDB_ID.ROOT, 'Dimensions')
local nBottomLay = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode..sNamePart1)
local nRefBottom = EgtGetFirstNameInGroup(nBottomLay, 'Ref')
local nRef = EgtGetFirstNameInGroup(nRefBottom, sNameRef1)
local pt1 = EgtSP( nRef, GDB_RT.GRID)
local nTopLay = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode..sNamePart2)
local nRefTop = EgtGetFirstNameInGroup(nTopLay, 'Ref')
nRef = EgtGetFirstNameInGroup(nRefTop, sNameRef2)
local pt2 = EgtSP( nRef, GDB_RT.GRID)
local ptMid = (pt1 + pt2) / 2 + ptOffset
local nDim = EgtAlignedDimension( nDimLay, pt1, pt2, ptMid, sNameDimension, GDB_RT.GRID)
EgtSetColor( nDim, EgtStdColor( 'YELLOW'))
EgtRelocate(nDim, GDB_RT.GRID)
EgtSetName(nDim, sNameDimension)
end
local function SetReference()
-- Per accoppiamento Left-Bottom
CreateReference( tbName[1], 'OutLoop', 'A4', 'R1')
-- Per accoppiamento di right su bottom
CreateReference( tbName[1], 'OutLoop', 'A2', 'R2')
-- Per accoppiamento di back su bottom
CreateReference( tbName[1], 'OutLoop', 'A3', 'R3', CMP.SBA, '0,-x,0')
-- setto le info di accoppiamento per il PartLeft
CreateReference( tbName[2], 'OutLoop', 'A2', 'R1', CMP.SL, '0,0,-x')
SetPairInfo( tbName[2], 'R1', tbName[1], 'R1', -1, 90, 1)
-- setto le info per l'accoppiamento del top sul left
CreateReference( tbName[2], 'OutLoop', 'A4', 'R2', CMP.SL, '0,0,-x')
-- setto le info per l'accoppiamento del back sul left
CreateReference( tbName[2], 'OutLoop', 'A3', 'R3', CMP.SL, '0,0,0')
-- setto le info di accoppiamento del PartRight
SetPairInfo( tbName[3], 'R1', tbName[1], 'R2', -1, 90, 2)
CreateReference( tbName[3], 'OutLoop', 'A4', 'R1', CMP.SR, '0,0,-x')
-- setto le info di accoppiamento del PartTop
SetPairInfo( tbName[4], 'R1', tbName[2], 'R2', -1, 90, 1)
CreateReference( tbName[4], 'OutLoop', 'A2', 'R1')
-- setto le info di accoppiamento del PartBack
SetPairInfo( tbName[5], 'R1', tbName[2], 'R3', -1, 90)
CreateReference( tbName[5], 'OutLoop', 'A1', 'R1', CMP.SBA, '0,0,-x')
-- 1° punto di riferimento per la dimensione dell'altezza
CreatePointReference( tbName[1], 'OutLoop', 'A1', 'R4', 0, CMP.SB, '0,0,-x')
-- 2° punto di riferimento per la quota dell'altezza ( e 1° per la lunghezza)
CreatePointReference( tbName[4], 'OutLoop', 'A1', 'R2', 1, CMP.ST, '0,0,-x')
-- 2° riferimento per la lunghezza ( e 1° per la profondità)
CreatePointReference( tbName[4], 'OutLoop', 'A1', 'R3', 0, CMP.ST, '0,0,-x')
-- 2° riferimento per la profondità
CreatePointReference( tbName[4], 'OutLoop', 'A4', 'R4', 0, CMP.ST, '0,0,-x')
end
local function AddDimensions()
local GridFr = Frame3d(ORIG(),GDB_FR.FRONT)
-- la dimensione dell'altezza ( R4 di Bottom e R2 di Top)
DrawLineraDimension( tbName[1], 'R4', tbName[4], 'R2', 'SUA ALTEZZA',GridFr, Point3d(-50,0,0))
--dimensione della lunghezza ( R2 del Top e R3 del Top)
GridFr = Frame3d(ORIG(),GDB_FR.TOP)
DrawLineraDimension( tbName[4], 'R2', tbName[4], 'R3', 'LARGHEZZA',GridFr, Point3d(0,-50,0))
-- dimensione della profondità ( R3 del Top e R4 del Top)
GridFr = Frame3d(ORIG(),GDB_FR.TOP)
DrawLineraDimension( tbName[4], 'R3', tbName[4], 'R4', 'PROFONDITÀ',GridFr, Point3d(50,0,0))
EgtSetGridFrame(GLOB_FRM())
end
-- Confronto i dati del fiel .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
function CMP_Draw(bPreview)
local bRedraw = IsDataChanged()
if bRedraw then
-- pulisco il file e leggo i dati
EgtNewFile()
HorizontalOffset = 0
CMP.A = CMP.V1 -- altezza
CMP.L = CMP.V2 -- lunghezza
CMP.P = CMP.V3 -- profondità
CMP.ST = CMP.V4 -- spessore top
CMP.SB = CMP.V5 -- spessore bottom
CMP.SL = CMP.V6 -- spessore left
CMP.SR = CMP.V7 -- spessore right
CMP.SBA = CMP.V8 -- spessore back
-- Costruisco i Part per ogni pezzo
CreateLayers()
-- Definisco le dimensioni dei rettangoli per costruire gli OutLoop
local tbDimension={{CMP.L,CMP.P,0},
{CMP.A-(CMP.ST+CMP.SB), CMP.P,0},
{CMP.A-(CMP.ST+CMP.SB), CMP.P,0},
{CMP.L,CMP.P,0},
{CMP.A-(CMP.ST+CMP.SB), CMP.L-(CMP.SL + CMP.SR),0}}
local tbTh={CMP.SB, CMP.SL, CMP.SR, CMP.ST, CMP.SBA}
-- Recupero il primo Part
local nIdP = EgtGetFirstPart()
local nCount = 1
while nIdP do
local sName = EgtGetName(nIdP)
if sName ~= 'Dimensions' and sName ~= 'SOLID' then
-- Recupero tabella Layer del pezzo
local tbLayer = FindLayers( nIdP)
-- Costruisco Layer OutLoop
local IdLoop = EgtRectangle2P(tbLayer['Aux'],{0,0,0}, tbDimension[nCount],GDB_RT.GLOB)
CreatePart(tbLayer, tbName[nCount], IdLoop,tbTh[nCount], HorizontalOffset)
-- Costruisco Layer InLoop
IdLoop = EgtRectangle2P(tbLayer['Aux'],{20,20,0}, {220,220,0},GDB_RT.GLOB)
CreatePart(tbLayer, tbName[nCount], IdLoop, tbTh[nCount], HorizontalOffset, true)
nCount = nCount + 1
end
nIdP = EgtGetNext(nIdP)
end
SetReference()
if CMP.DrawSolid then
local sPath = ""
sPath = EgtGetStringFromIni( "Vein3D", "Vein3D_Dir", "", EgtGetIniFile())
EgtOutLog(''..sPath)
loadfile(sPath ..'\\'.. "CreateSOLID_FromPartsInPark.lua")({AutoRun=true})
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()) ..'\\'.. "FUCK.nge")
end
end
--CMP_Draw()
_G.CMP_Draw = CMP_Draw