739 lines
28 KiB
Lua
739 lines
28 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 = 20
|
|
CMP.N5 = 'Spessore Bottom' -- spessore bottom
|
|
CMP.T5 = 3
|
|
CMP.V5 = 20
|
|
CMP.N6 = 'Spessore Left' -- spessore left
|
|
CMP.T6 = 3
|
|
CMP.V6 = 8
|
|
CMP.N7 = 'Spessore Right' -- spessore right
|
|
CMP.T7 = 3
|
|
CMP.V7 = 6
|
|
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()
|
|
|
|
-- Percorso direttorio Vein3D
|
|
local sPath = ""
|
|
sPath = EgtGetStringFromIni( "Vein3D", "Vein3D_Dir", "", EgtGetIniFile())
|
|
EgtOutLog(' → '..sPath)
|
|
|
|
-- 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()).."_"
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------
|
|
-- FUNZIONI BASE PER GENERARE I COMPO SOLID INIZIO
|
|
-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
local function SaveMEPlease()
|
|
EgtSaveFile('c:\\EgtData\\OmagOFFICE\\Vein3D\\FOO.nge')
|
|
end
|
|
|
|
-- CREAZIONE dei Layer di un singolo Part
|
|
-- I nomi dei layer sono: OutLoop, Region, Ref, Labels, Aux
|
|
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 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')
|
|
EgtOutLog(' Creo Part: '..sUNICode..PartName)
|
|
SaveMEPlease()
|
|
return Pz
|
|
end
|
|
--
|
|
|
|
-- RESTITUISCE una tabella con gli Id dei layer costruiti nella funzione CreatePartLayer part,
|
|
-- Se il nome del Part non esiste restituice 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['Region'] = EgtGetFirstNameInGroup(IdPart, 'Region')
|
|
tbLayer['Ref'] = EgtGetFirstNameInGroup(IdPart, 'Ref')
|
|
tbLayer['Labels'] = EgtGetFirstNameInGroup(IdPart, 'Labels')
|
|
tbLayer['Aux'] = EgtGetFirstNameInGroup(IdPart, 'Aux')
|
|
return tbLayer
|
|
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)
|
|
if nEdges == 1 then
|
|
EgtSetInfo(nId, 'PrevAng', 0)
|
|
EgtSetInfo(nId, 'NextAng', 0)
|
|
return
|
|
end
|
|
for i = 1, nEdges do
|
|
-- recupero i dati
|
|
local vtCurrS = EgtSV(nId, GDB_RT.GLOB)
|
|
local vtPrevE = EgtEV(nPrevId, GDB_RT.GLOB)
|
|
local vtCurrE = EgtEV(nId, GDB_RT.GLOB)
|
|
local vtNextS = EgtSV(nNextId, GDB_RT.GLOB)
|
|
local vtAx = Z_AX()
|
|
if bInLoop then vtAx=-vtAx end
|
|
local NextAng = GetRotation( vtCurrE, vtNextS, vtAx)
|
|
local PrevAng = GetRotation( vtPrevE, 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
|
|
--
|
|
|
|
-- DEVO RICEVERE SOLO UN CONTORNO!! Da semplificare
|
|
-- 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
|
|
local tbIdLoop = {}
|
|
while nEdge do
|
|
local tbName = EgtNumToString(nCount)
|
|
EgtSetName( nEdge, "A"..tbName)
|
|
nCount = nCount + 1
|
|
table.insert( tbIdLoop, nEdge)
|
|
nEdge = EgtGetNext(nEdge)
|
|
end
|
|
-- Ricavo info direzioni
|
|
SetMachiningInfo(nLay,bInLoop)
|
|
return tbIdLoop
|
|
end
|
|
--
|
|
|
|
-- CREAZIONE LAyer per le dimensioni
|
|
local function CreateLayerDimension()
|
|
local Pz = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC) -- layer dimensioni e etichette
|
|
EgtSetName( Pz, 'Dimensions')
|
|
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
|
|
--
|
|
|
|
-- Creazione del part assegnato un contorno esploso:
|
|
-- tbLayer : tabella dei layer (FindLayers dato il Part)
|
|
-- sName : nome da assegnare in grafica
|
|
-- tbIdEntCrv: tabella delle entità che costituiscono il contorno (da ExplodeAndNameEdges)
|
|
-- dTh : spessore pezzo
|
|
-- dOffset : per messa in piano dei pezzi (0 se non si usa)
|
|
-- bInLoop : tipo di contorno
|
|
local function CreatePart(tbLayer, sName, tbIdEntCrv, dTh, dOffset, bInLoop)
|
|
-- recupero il layer del contorno
|
|
local IdCurrLayer = EgtGetParent( tbIdEntCrv[1])
|
|
-- recupero l'Id del part
|
|
local IdPart = EgtGetParent( IdCurrLayer)
|
|
-- costruisco il contorno chiuso
|
|
local IdLoop = EgtCurveCompoByChain( IdCurrLayer, tbIdEntCrv, EgtSP(tbIdEntCrv[1],GDB_RT.GLOB), false, 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 bInLoop 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
|
|
-- elimino il contorno chiuso
|
|
EgtErase(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 DrawLinearDimension( 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
|
|
--
|
|
-------------------------------------------------------------------------------------------------------------------------
|
|
-- FUNZIONI BASE PER GENERARE I COMPO SOLID FINE
|
|
-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------
|
|
-- 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 ImportOutLoop( 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 AFLLITA MISERAMENTE: '..tostring(IdLoop)..';'..tostring(OutLayer))
|
|
end
|
|
EgtErase(LastPart)
|
|
local tbIdLoop = ExplodeAndNameEdges( IdLoop)
|
|
|
|
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)
|
|
SaveMEPlease()
|
|
-- definizione SideAng
|
|
-- EgtSetInfo( tbIdLoop[1], 'OrigSideAng', 45)
|
|
return tbIdLoop
|
|
end
|
|
--
|
|
|
|
-- Crea un contorno chiuso rettangolare come OutLoop (con diagonale da origine a ptEND)
|
|
function CreateWaterfall( tbLayer, sNameLayer, ptEND, PrevAng, NextAng, bIsPrevWaterfall, bIsNextWaterfall)
|
|
local OffseAng = 3
|
|
local NAng = NextAng/2 + OffseAng
|
|
local PAng = PrevAng/2 + OffseAng
|
|
if not bIsNextWaterfall then
|
|
if NAng >= 0 then
|
|
NAng = -90 + NextAng
|
|
else
|
|
NAng = -90 - NextAng
|
|
end
|
|
end
|
|
if not bIsPrevWaterfall then
|
|
if PAng >= 0 then
|
|
PAng = -90 + PrevAng
|
|
else
|
|
PAng = -90 - PrevAng
|
|
end
|
|
end
|
|
local IdLoop = EgtRectangle2P(tbLayer[sNameLayer],{0,0,0}, ptEND,GDB_RT.GLOB)
|
|
local tbIdLoop = ExplodeAndNameEdges( IdLoop)
|
|
-- definizione SideAng
|
|
-- bla bla bla---------------------------------------------------------------------------------------------------
|
|
EgtSetInfo( tbIdLoop[2], 'OrigSideAng', -NAng)
|
|
EgtSetInfo( tbIdLoop[2], 'SideAng', -NAng)
|
|
EgtSetInfo( tbIdLoop[4], 'OrigSideAng', -PAng)
|
|
EgtSetInfo( tbIdLoop[4], 'SideAng', -PAng)
|
|
-- bla bla bla---------------------------------------------------------------------------------------------------
|
|
return tbIdLoop
|
|
end
|
|
--
|
|
-- Crea un contorno chiuso rettangolare come OutLoop (con diagonale da origine a ptEND)
|
|
function CreateSplashtop( tbLayer, sNameLayer, ptEND, PrevAng, NextAng, bIsPrevSplashtop, bIsNextSplashtop, Th)
|
|
local OffseAng = 3
|
|
local NAng = NextAng/2 + OffseAng
|
|
local PAng = PrevAng/2 + OffseAng
|
|
if not bIsNextWaterfall then
|
|
if NAng >= 0 then
|
|
NAng = 90 - NextAng
|
|
else
|
|
NAng = 90 + NextAng
|
|
end
|
|
end
|
|
if not bIsPrevWaterfall then
|
|
if PAng >= 0 then
|
|
PAng = 90 - PrevAng
|
|
else
|
|
PAng = 90 + PrevAng
|
|
end
|
|
end
|
|
EgtOutLog(PAng)
|
|
EgtOutLog(NAng)
|
|
-- allarghiamo il pezzo
|
|
ptEND[1] = ptEND[1] + Th*(sin(NAng) + sin(PAng))
|
|
--ptEND[1] = ptEND[1] + Th*(sin(NAng) + sin(PAng)) - Th/cos(NAng)
|
|
local IdLoop = EgtRectangle2P(tbLayer[sNameLayer],{0,0,0}, ptEND,GDB_RT.GLOB)
|
|
local tbIdLoop = ExplodeAndNameEdges( IdLoop)
|
|
-- definizione SideAng
|
|
-- bla bla bla---------------------------------------------------------------------------------------------------
|
|
EgtSetInfo( tbIdLoop[2], 'OrigSideAng', -NAng)
|
|
EgtSetInfo( tbIdLoop[2], 'SideAng', -NAng)
|
|
EgtSetInfo( tbIdLoop[4], 'OrigSideAng', -PAng)
|
|
EgtSetInfo( tbIdLoop[4], 'SideAng', -PAng)
|
|
-- bla bla bla---------------------------------------------------------------------------------------------------
|
|
return tbIdLoop, PAng, NAng, Th*sin(PAng)
|
|
end
|
|
--
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------
|
|
-- CREAZIONE/IMPORTAZIONE Loop FINE
|
|
-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
local function GetInfoSplahtopOrWaterfall()
|
|
local tbSplWf = {}
|
|
-- ...
|
|
return tbSplWf
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------
|
|
-- METODI AUSILIARI LOCALI INIZIO
|
|
-------------------------------------------------------------------------------------------------------------------------
|
|
-- Restituisce l'angolo precedente e successivo dell'aentità passata
|
|
local function GetPrevNextAng(IdEnt)
|
|
local PrevAng = EgtGetInfo(IdEnt,'PrevAng','d') or 0
|
|
local NextAng = EgtGetInfo(IdEnt,'NextAng','d') or 0
|
|
return PrevAng, NextAng
|
|
end
|
|
--
|
|
-- Verifica se esiste un Waterfall successivo a quallo corrente (i-esimo) della lista passata
|
|
local function IsNextWaterfall(tbIdLoop, i)
|
|
i = i+1
|
|
if i > #tbIdLoop then i = 1 end
|
|
local nVal = EgtGetInfo(tbIdLoop[i], 'AF', 'i') or 0
|
|
if nVal == 2 then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
--
|
|
-- Verifica se esiste un Waterfall precedente a quallo corrente (i-esimo) della lista passata
|
|
local function IsPrevWaterfall(tbIdLoop, i)
|
|
i = i-1
|
|
if i < 1 then i = #tbIdLoop end
|
|
local nVal = EgtGetInfo(tbIdLoop[i], 'AF', 'i') or 0
|
|
if nVal == 2 then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
--
|
|
-- Verifica se esiste un Splashtop successivo a quallo corrente (i-esimo) della lista passata
|
|
local function IsNextSplashtop(tbIdLoop, i)
|
|
i = i+1
|
|
if i > #tbIdLoop then i = 1 end
|
|
local nVal = EgtGetInfo(tbIdLoop[i], 'AF', 'i') or 0
|
|
if nVal == 1 then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
--
|
|
-- Verifica se esiste un Splashtop precedente a quallo corrente (i-esimo) della lista passata
|
|
local function IsPrevSplashtop(tbIdLoop, i)
|
|
i = i-1
|
|
if i < 1 then i = #tbIdLoop end
|
|
local nVal = EgtGetInfo(tbIdLoop[i], 'AF', 'i') or 0
|
|
if nVal == 1 then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
-------------------------------------------------------------------------------------------------------------------------
|
|
-- METODI AUSILIARI LOCALI FINE
|
|
-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
-- 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 or not CMP.DrawSolid 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
|
|
|
|
-- PIANO POLLO
|
|
local Pz_Top = CreatePartLayer( 'TopChicken')
|
|
-- Creo il contorno esterno
|
|
local tbIdLoop = ImportOutLoop( FindLayers( Pz_Top), sPath ..'\\'.. 'TopChicken.nge')
|
|
-- Creo il pezzo dato il contorno
|
|
CreatePart( FindLayers( Pz_Top), 'TopChicken', tbIdLoop, CMP.ST, 0)
|
|
|
|
for i=1, #tbIdLoop do
|
|
local nVal = EgtGetInfo(tbIdLoop[i], 'AF', 'i') or 0
|
|
if nVal == 2 then
|
|
-- WATERFALL
|
|
local dH = 100
|
|
local sNamePz = 'A'.. tostring(i)..'Waterfall'
|
|
local Pz_A = CreatePartLayer(sNamePz)
|
|
local dLen = EgtCurveLength(tbIdLoop[i])
|
|
local PAng, NAng = GetPrevNextAng(tbIdLoop[i])
|
|
local tbIdLoopWF = CreateWaterfall( FindLayers(Pz_A), 'OutLoop', {dLen, dH,0}, PAng, NAng, IsPrevWaterfall(tbIdLoop, i), IsNextWaterfall(tbIdLoop, i))
|
|
CreatePart( FindLayers(Pz_A), sNamePz, tbIdLoopWF, CMP.ST, 0)
|
|
CreateReference( 'TopChicken', 'OutLoop', 'A'..tostring(i), 'R'..tostring(i), CMP.ST, '0,0,-x')
|
|
CreateReference(sNamePz, 'OutLoop', 'A3', 'R3', CMP.ST, '0,0,0')
|
|
SetPairInfo(sNamePz, 'R3', 'TopChicken', 'R'..tostring(i), -1, -90, 1)
|
|
|
|
elseif nVal == 1 then
|
|
-- SPLASHTOP
|
|
local dH = 200
|
|
local sNamePz = 'A'.. tostring(i)..'Splahtop'
|
|
local Pz_A = CreatePartLayer(sNamePz)
|
|
local dLen = EgtCurveLength(tbIdLoop[i])
|
|
local PAng, NAng = GetPrevNextAng(tbIdLoop[i])
|
|
local tbIdLoopWF, PAng, dLenOffset = CreateSplashtop( FindLayers(Pz_A), 'OutLoop', {dLen, dH,0}, PAng, NAng, IsPrevSplashtop(tbIdLoop, i), IsNextSplashtop(tbIdLoop, i), CMP.ST)
|
|
CreatePart( FindLayers(Pz_A), sNamePz, tbIdLoopWF, CMP.ST, 0)
|
|
CreateReference( 'TopChicken', 'OutLoop', 'A'..tostring(i), 'R'..tostring(i), CMP.ST, '0,0,0')
|
|
CreateReference(sNamePz, 'OutLoop', 'A3', 'R3', CMP.ST, tostring(dLenOffset)..',0,-x')
|
|
--CreateReference(sNamePz, 'OutLoop', 'A3', 'R3', CMP.ST, '0,0,-x')
|
|
SetPairInfo(sNamePz, 'R3', 'TopChicken', 'R'..tostring(i), -1, 90, 2)
|
|
end
|
|
end
|
|
|
|
CreateLayerDimension()
|
|
SetReference()
|
|
|
|
if CMP.DrawSolid then
|
|
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
|
|
SaveMEPlease()
|
|
end
|
|
end
|
|
|
|
--CMP_Draw()
|
|
|
|
_G.CMP_Draw = CMP_Draw
|