From 5ce9e807f234dae905a0c23656a2e09c594b961e Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Wed, 4 Dec 2024 16:45:33 +0100 Subject: [PATCH] seprazione del template cabinet dal template piano cucina. --- Cabinet.lua | 301 ++++++++------------ TopChicken.lua | 734 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 847 insertions(+), 188 deletions(-) create mode 100644 TopChicken.lua diff --git a/Cabinet.lua b/Cabinet.lua index 5adde93..04b096a 100644 --- a/Cabinet.lua +++ b/Cabinet.lua @@ -23,16 +23,16 @@ CMP.T3 = 3 CMP.V3 = 300 CMP.N4 = 'Spessore Top' -- spessore top CMP.T4 = 3 -CMP.V4 = 20 +CMP.V4 = 6 CMP.N5 = 'Spessore Bottom' -- spessore bottom CMP.T5 = 3 -CMP.V5 = 20 +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 = 6 +CMP.V7 = 65 CMP.N8 = 'Spessore Back' -- spessore back CMP.T8 = 3 CMP.V8 = 7 @@ -77,10 +77,6 @@ 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\\FUCK.nge') -end - -- CREAZIONE dei Layer di un singolo Part -- I nomi dei layer sono: OutLoop, Region, Ref, Labels, Aux local function CreatePartLayer(PartName) @@ -98,9 +94,6 @@ local function CreatePartLayer(PartName) EgtSetName(LLabel,'Labels') local LAux= EgtGroup(Pz,GDB_RT.LOC) -- layer etichette EgtSetName(LAux,'Aux') - EgtOutLog(' Creo Part: '..sUNICode..PartName) - SaveMEPlease() - return Pz end -- @@ -215,8 +208,12 @@ local function ExplodeAndNameEdges( IdLoop, bInLoop) end -- --- CREAZIONE LAyer per le dimensioni -local function CreateLayerDimension() +-- RIMUOVERE!! NON necessario! +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 @@ -455,20 +452,56 @@ end -- 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') + -- 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') - SaveMEPlease() + -- 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) - --Esempio: - -- DrawLinearDimension( tbName[1], 'R4', tbName[4], 'R2', 'SUA ALTEZZA',GridFr, Point3d(-50,0,0)) + -- la dimensione dell'altezza ( R4 di Bottom e R2 di Top) + DrawLinearDimension( 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) + DrawLinearDimension( 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) + DrawLinearDimension( tbName[4], 'R3', tbName[4], 'R4', 'PROFONDITÀ',GridFr, Point3d(50,0,0)) + EgtSetGridFrame(GLOB_FRM()) end -- @@ -480,167 +513,68 @@ end -- 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 +function ImportOutLoop( tbLayer) + local OutLayer = EgtGetParent(tbLayer['OutLoop']) + EgtInsertFile( sPath ..'\\'.. 'TopChicken.nge') -- recupero ultimo Part - local LastPart = EgtGetLastPart() - local FstLayerInLstPart = EgtGetFirstGroupInGroup( LastPart) + local LstPart = EgtGetLastPart() + local FstLayerInLstPart = EgtGetFirstGroupInGroup( LstPart) local IdLoop = EgtGetFirstInGroup( FstLayerInLstPart) - if not EgtRelocateGlob( IdLoop, OutLayer) then - EgtOutLog(' RELOCATE AFLLITA MISERAMENTE: '..tostring(IdLoop)..';'..tostring(OutLayer)) - end - EgtErase(LastPart) + EgtRelocateGlob( IdLoop, OutLayer) 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 + -- bla bla bla--------------------------------------------------------------------------------------------------- -- EgtSetInfo( tbIdLoop[1], 'OrigSideAng', 45) + -- EgtSetInfo( tbIdLoop[1], 'SideAng', 45) + -- bla bla bla--------------------------------------------------------------------------------------------------- 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 +function CreateLoop( tbLayer, sNameLayer, ptEND) + if sNameLayer == 'InLoop' then + local LIn = EgtGroup( EgtGetParent(tbLayer['OutLoop']),GDB_RT.LOC) -- layer della figura principale + EgtSetName(LIn,'InLoop') 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) + -- EgtSetInfo( tbIdLoop[1], 'OrigSideAng', 45) + -- EgtSetInfo( tbIdLoop[1], 'SideAng', 45) -- 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) - 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 + +-- Crea un contorno chiuso rettangolare come InLoop (dimensione fissata) +function CreateBore( tbLayer, sNameLayer) + local LIn + if sNameLayer == 'InLoop' then + LIn = EgtGroup( EgtGetParent(tbLayer['OutLoop']),GDB_RT.LOC) -- layer della figura principale + EgtSetName(LIn,'InLoop') end - if not bIsPrevWaterfall then - if PAng >= 0 then - PAng = 90 - PrevAng - else - PAng = 90 + PrevAng - end - end - EgtOutLog(PAng) - EgtOutLog(NAng) - local IdLoop = EgtRectangle2P(tbLayer[sNameLayer],{0,0,0}, ptEND,GDB_RT.GLOB) + local IdLoop = EgtRectangle2P(LIn,{20,20,0}, {120,120,0},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) + EgtSetInfo( tbIdLoop[1], 'OrigSideAng', 20) + EgtSetInfo( tbIdLoop[1], 'SideAng', 20) + EgtSetInfo( tbIdLoop[2], 'OrigSideAng', 20) + EgtSetInfo( tbIdLoop[2], 'SideAng', 20) + EgtSetInfo( tbIdLoop[3], 'OrigSideAng', 20) + EgtSetInfo( tbIdLoop[3], 'SideAng', 20) + EgtSetInfo( tbIdLoop[4], 'OrigSideAng', 20) + EgtSetInfo( tbIdLoop[4], 'SideAng', 20) -- bla bla bla--------------------------------------------------------------------------------------------------- - return tbIdLoop, PAng, NAng + return tbIdLoop 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 @@ -670,45 +604,36 @@ function CMP_Draw(bPreview) 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 = CreateSplashtop( FindLayers(Pz_A), 'OutLoop', {dLen, dH,0}, PAng, NAng, IsPrevSplashtop(tbIdLoop, i), IsNextSplashtop(tbIdLoop, i)) - 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(sin(PAng)*CMP.ST)..',0,-x') - SetPairInfo(sNamePz, 'R3', 'TopChicken', 'R'..tostring(i), -1, 90, 1) + -- 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 tbIdLoop = CreateLoop( tbLayer, 'OutLoop', tbDimension[nCount]) + CreatePart(tbLayer, tbName[nCount], tbIdLoop, tbTh[nCount], HorizontalOffset) + + -- -- Costruisco Layer InLoop + -- IdLoop = EgtRectangle2P(tbLayer['Aux'],{20,20,0}, {220,220,0},GDB_RT.GLOB) + tbIdLoop = CreateBore( tbLayer, 'InLoop') + CreatePart(tbLayer, tbName[nCount], tbIdLoop, 0, 0, true) + + nCount = nCount + 1 end + nIdP = EgtGetNext(nIdP) end - - CreateLayerDimension() SetReference() if CMP.DrawSolid then diff --git a/TopChicken.lua b/TopChicken.lua new file mode 100644 index 0000000..5adde93 --- /dev/null +++ b/TopChicken.lua @@ -0,0 +1,734 @@ +-- 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\\FUCK.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) + 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) + 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 +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 = CreateSplashtop( FindLayers(Pz_A), 'OutLoop', {dLen, dH,0}, PAng, NAng, IsPrevSplashtop(tbIdLoop, i), IsNextSplashtop(tbIdLoop, i)) + 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(sin(PAng)*CMP.ST)..',0,-x') + SetPairInfo(sNamePz, 'R3', 'TopChicken', 'R'..tostring(i), -1, 90, 1) + 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 + EgtSaveFile(EgtGetStringFromIni( "Vein3D", "Vein3D_Dir", "", EgtGetIniFile()) ..'\\'.. "FOO.nge") + end +end + +--CMP_Draw() + +_G.CMP_Draw = CMP_Draw