- impostato il check per la rigenerazione della scena solo se i dati sono cambiati

- aggiunti controlli
- accoprato il codice in funzioni
- aggiunti commenti.
This commit is contained in:
Daniele Bariletti
2024-12-02 10:41:28 +01:00
parent 8195c4f39a
commit b307f76f63
+420 -225
View File
@@ -15,7 +15,7 @@ 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 = 'Lunghezza' -- lunghezza
CMP.N2 = 'Larghezza' -- larghezza
CMP.T2 = 3
CMP.V2 = 600
CMP.N3 = 'Profondità' -- profondità
@@ -44,53 +44,95 @@ 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()
local tbName = {"Bottom", "Left", "Right", "Top", "Back"}
-- 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
local Pz = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC) -- pezzo
EgtSetName( Pz, sUNICode..tbName[i])
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 LRef = EgtGroup(Pz,GDB_RT.LOC) -- layer riferimenti
EgtSetName(LRef,"Labels")
CreatePartLayer(tbName[i])
end
local Pz = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC) -- layer dimensioni e etichette
EgtSetName( Pz, "Dimensions")
EgtSetName( Pz, 'Dimensions')
end
--
local function FindLayers( IdPart)
local tbLayer = {}
tbLayer["OutLoop"] = EgtGetFirstNameInGroup(IdPart, "OutLoop")
tbLayer["Region"] = EgtGetFirstNameInGroup(IdPart, "Region")
tbLayer["Ref"] = EgtGetFirstNameInGroup(IdPart, "Ref")
tbLayer["Labels"] = EgtGetFirstNameInGroup(IdPart, "Labels")
return tbLayer
end
local function ExplodeAndNameEdges( IdLoop)
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
end
local function SetMachiningInfo(Layer)
-- 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)
@@ -101,11 +143,13 @@ local function SetMachiningInfo(Layer)
local vtCurrS = EgtSV(nId, GDB_RT.GLOB)
local vtPrevS = EgtSV(nPrevId, GDB_RT.GLOB)
local vtNextS = EgtSV(nNextId, GDB_RT.GLOB)
local NextAng = GetAngle( vtCurrS, vtNextS)
local PrevAng = GetAngle( vtPrevS, vtCurrS)
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)
EgtSetInfo(nId, 'PrevAng', PrevAng)
EgtSetInfo(nId, 'NextAng', NextAng)
-- aggiorno gli id
nPrevId = nId
nId = nNextId
@@ -115,191 +159,337 @@ local function SetMachiningInfo(Layer)
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
local function CreatePart(Part, sName, ptDiag, dTh, dOffset)
local tbLayer = FindLayers( Part)
local IdLoop = EgtRectangle2P(tbLayer["OutLoop"],{0,0,0},ptDiag,GDB_RT.GLOB)
local IdReg = EgtSurfFlatRegion(tbLayer["Region"],IdLoop)
EgtSetInfo(Part, "Th", dTh)
EgtSetInfo(Part, "Paired",tostring(Part))
-- 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)
SetMachiningInfo(tbLayer["OutLoop"])
-- 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(ptDiag)/2
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)
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)
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(Part,vtMove, GDB_RT.GLOB)
HorizontalOffset = HorizontalOffset + Point3d(ptDiag):getX()
--EgtMove(IdPart,vtMove, GDB_RT.GLOB)
HorizontalOffset = HorizontalOffset + Point3d(ptDiagEnd):getX()
end
local function SetReference()
-- creo i ref del part bottom
local nPart = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode.."Bottom")
local tbLayer = FindLayers( nPart)
--accoppiamento di left su bottom
local nEdge = EgtGetFirstNameInGroup(tbLayer["OutLoop"], "A4")
local nRef = EgtCopy( nEdge, tbLayer["Ref"])
EgtSetName( nRef, "R1")
-- accoppiamento di right su bottom
nEdge = EgtGetFirstNameInGroup(tbLayer["OutLoop"], "A2")
nRef = EgtCopy( nEdge, tbLayer["Ref"])
EgtSetName( nRef, "R2")
-- accoppiamento di back su bottom
nEdge = EgtGetFirstNameInGroup(tbLayer["OutLoop"], "A3")
nRef = EgtCopy( nEdge, tbLayer["Ref"])
EgtSetName(nRef, "R3")
EgtSetInfo(nRef, "Var", CMP.SBA)
EgtSetInfo(nRef, "Dir", "0,-x,0")
-- 1o riferimento per la dimensione dell'altezza
nEdge = EgtGetFirstNameInGroup(tbLayer["OutLoop"], "A1")
local pt = EgtSP(nEdge, GDB_RT.GLOB)
nRef = EgtPoint( tbLayer["Ref"], pt, GDB_RT.GLOB)
EgtSetName(nRef, "R4")
EgtSetInfo(nRef, "Var", CMP.SB)
EgtSetInfo(nRef, "Dir", "0,0,-x")
-- setto le info di accoppiamento per il PartLeft
nPart = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode.."Left")
EgtSetInfo(nPart, "PairMyRef", "R1")
EgtSetInfo(nPart, "PairToRef", sUNICode.."Bottom".."_".."R1")
EgtSetInfo(nPart, "PairSpin", -1)
EgtSetInfo(nPart, "PairAng", 90)
EgtSetInfo(nPart, "PairMode", 1)
tbLayer = FindLayers( nPart)
nEdge = EgtGetFirstNameInGroup(tbLayer["OutLoop"], "A2")
nRef = EgtCopy( nEdge, tbLayer["Ref"])
EgtSetName(nRef, "R1")
EgtSetInfo(nRef, "Var", CMP.SL)
EgtSetInfo(nRef, "Dir", "0,0,-x")
-- setto le info per l'accoppiamento del top sul left
nEdge = EgtGetFirstNameInGroup(tbLayer["OutLoop"], "A4")
nRef = EgtCopy( nEdge, tbLayer["Ref"])
EgtSetName(nRef, "R2")
EgtSetInfo(nRef, "Var", CMP.SL)
EgtSetInfo(nRef, "Dir", "0,0,-x")
-- setto le info di accoppiamento del PartRight
nPart = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode.."Right")
EgtSetInfo(nPart, "PairMyRef", "R1")
EgtSetInfo(nPart, "PairToRef", sUNICode.."Bottom".."_".."R2")
EgtSetInfo(nPart, "PairSpin", -1)
EgtSetInfo(nPart, "PairAng", 90)
EgtSetInfo(nPart, "PairMode", 2)
tbLayer = FindLayers( nPart)
nEdge = EgtGetFirstNameInGroup(tbLayer["OutLoop"], "A4")
nRef = EgtCopy( nEdge, tbLayer["Ref"])
EgtSetName(nRef, "R1")
EgtSetInfo(nRef, "Var", CMP.SR)
EgtSetInfo(nRef, "Dir", "0,0,-x")
-- setto le info di accoppiamento del PartTop
nPart = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode.."Top")
EgtSetInfo(nPart, "PairMyRef", "R1")
EgtSetInfo(nPart, "PairToRef", sUNICode.."Left".."_".."R2")
EgtSetInfo(nPart, "PairSpin", -1)
EgtSetInfo(nPart, "PairAng", 90)
EgtSetInfo(nPart, "PairMode", 1)
tbLayer = FindLayers( nPart)
nEdge = EgtGetFirstNameInGroup(tbLayer["OutLoop"], "A2")
nRef = EgtCopy( nEdge, tbLayer["Ref"])
EgtSetName(nRef, "R1")
-- 2o riferimento per la quota dell'altezza ( e 1o per la lunghezza)
nEdge = EgtGetFirstNameInGroup(tbLayer["OutLoop"], "A1")
pt = EgtEP(nEdge, GDB_RT.GLOB)
nRef = EgtPoint( tbLayer["Ref"], pt, GDB_RT.GLOB)
EgtSetName(nRef, "R2")
EgtSetInfo(nRef, "Var", CMP.ST)
EgtSetInfo(nRef, "Dir", "0,0,-x")
-- 2o riferimento per la lunghezza ( e 1o per la profondità)
nEdge = EgtGetFirstNameInGroup(tbLayer["OutLoop"], "A1")
pt = EgtSP(nEdge, GDB_RT.GLOB)
nRef = EgtPoint( tbLayer["Ref"], pt, GDB_RT.GLOB)
EgtSetName(nRef, "R3")
EgtSetInfo(nRef, "Var", CMP.ST)
EgtSetInfo(nRef, "Dir", "0,0,-x")
-- 2o riferimento per la profondità
nEdge = EgtGetFirstNameInGroup(tbLayer["OutLoop"], "A4")
pt = EgtSP(nEdge, GDB_RT.GLOB)
nRef = EgtPoint( tbLayer["Ref"], pt, GDB_RT.GLOB)
EgtSetName(nRef, "R4")
EgtSetInfo(nRef, "Var", CMP.ST)
EgtSetInfo(nRef, "Dir", "0,0,-x")
-- setto le info di accoppiamento del PartBack
nPart = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode.."Back")
EgtSetInfo(nPart, "PairMyRef", "R1")
EgtSetInfo(nPart, "PairToRef", sUNICode.."Bottom".."_".."R3")
EgtSetInfo(nPart, "PairSpin", -1)
EgtSetInfo(nPart, "PairAng", 90)
tbLayer = FindLayers( nPart)
nEdge = EgtGetFirstNameInGroup(tbLayer["OutLoop"], "A2")
nRef = EgtCopy( nEdge, tbLayer["Ref"])
EgtSetName(nRef, "R1")
--
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
--
local function MoveLabels()
-- 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")
local nChild = EgtGetInfo(nPartId, 'Child','i')
if nChild then
local nLaySource = EgtGetFirstNameInGroup(nPartId, "Labels")
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()
EgtSetGridFrame(Frame3d(ORIG(),GDB_FR.FRONT))
local nDimLay = EgtGetFirstNameInGroup(GDB_ID.ROOT, "Dimensions")
local GridFr = Frame3d(ORIG(),GDB_FR.FRONT)
-- la dimensione dell'altezza ( R4 di Bottom e R2 di Top)
local nBottomLay = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode.."Bottom")
local nRefBottom = EgtGetFirstNameInGroup(nBottomLay, "Ref")
local nRef = EgtGetFirstNameInGroup(nRefBottom, "R4")
local pt1 = EgtSP( nRef, GDB_RT.GRID)
local nTopLay = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode.."Top")
local nRefTop = EgtGetFirstNameInGroup(nTopLay, "Ref")
nRef = EgtGetFirstNameInGroup(nRefTop, "R2")
local pt2 = EgtSP( nRef, GDB_RT.GRID)
local ptMid = (pt1 + pt2) / 2 + Point3d(-50,0,0)
local nDim = EgtAlignedDimension( nDimLay, pt1, pt2, ptMid, "A", GDB_RT.GRID)
EgtRelocate(nDim, GDB_RT.GRID)
EgtSetName(nDim, "A")
DrawLineraDimension( tbName[1], 'R4', tbName[4], 'R2', 'SUA ALTEZZA',GridFr, Point3d(-50,0,0))
--dimensione della lunghezza ( R2 del Top e R3 del Top)
nRef = EgtGetFirstNameInGroup(nRefTop, "R2")
pt1 = EgtSP( nRef, GDB_RT.GLOB)
nRef = EgtGetFirstNameInGroup(nRefTop, "R3")
pt2 = EgtSP( nRef, GDB_RT.GLOB)
ptMid = (pt1 + pt2) / 2 + Point3d(0,-50,0)
nDim = EgtAlignedDimension( nDimLay, pt1, pt2, ptMid, "L", GDB_RT.GLOB)
EgtSetName(nDim, "L")
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)
nRef = EgtGetFirstNameInGroup(nRefTop, "R3")
pt1 = EgtSP( nRef, GDB_RT.GLOB)
nRef = EgtGetFirstNameInGroup(nRefTop, "R4")
pt2 = EgtSP( nRef, GDB_RT.GLOB)
ptMid = (pt1 + pt2) / 2 + Point3d(50,0,0)
--EgtSetGridFrame(Frame3d(pt1, GDB_FR.RIGHT))
nDim = EgtAlignedDimension( nDimLay, pt1, pt2, ptMid, "P", GDB_RT.GLOB)
EgtSetName(nDim, "P")
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()
return true
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)
@@ -316,49 +506,54 @@ function CMP_Draw(bPreview)
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()
local nIdP = EgtGetFirstPart()
local nCount = 1
-- 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}}
{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
CreatePart(nIdP, tbName[nCount], tbDimension[nCount],tbTh[nCount], HorizontalOffset)
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()
end
if CMP.DrawSolid then
local sPath = ""
sPath = EgtGetStringFromIni( "Vein3D", "Vein3D_Dir", "", EgtGetIniFile())
loadfile(sPath .. "CreateSOLID_FromPartsInPark.lua")({AutoRun=true})
MoveLabels()
-- local ASS = require("OperationOnSolid")
-- ASS.nVeinCtx = EgtGetContext()
-- local bDone = ASS.PairAll()
--loadfile("..\\OmagOFFICE\\Vein3D\\OperationOnSolid.lua")({AutoRun=true, nVeinCtx=EgtGetContext()})
loadfile(sPath .. "OperationOnSolid.lua")({AutoRun=true, nVeinCtx=EgtGetContext()})
AddDimensions()
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
-- Se non ci sono errori salvo i dati
if CMP.ERR == 0 then
-- scrivo i parametri nelle info del pezzo
WriteCompoDataToPart( Pz, CMP.Nome, CMP.Npar)
-- salvo i parametri come nuovo default
SaveCompoData(CMP.Npar)
end
--EgtSaveFile("D:\\Temp\\marmo\\cabinet.nge")
end
--CMP_Draw()