From 435fa8c0dfef45441c6e9844fb1d0efb3fd20e15 Mon Sep 17 00:00:00 2001 From: "carlo.baronchelli" Date: Wed, 4 Aug 2021 16:04:48 +0200 Subject: [PATCH] Aggiunto trianglo3L.lua alla cartella --- Frontalini_ecc/CompoAF/Alz&Front.lua | 2 +- Frontalini_ecc/CompoAF/Triangolo3L.lua | 177 +++++++++++++++++++++++++ 2 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 Frontalini_ecc/CompoAF/Triangolo3L.lua diff --git a/Frontalini_ecc/CompoAF/Alz&Front.lua b/Frontalini_ecc/CompoAF/Alz&Front.lua index 0019468..64b6199 100644 --- a/Frontalini_ecc/CompoAF/Alz&Front.lua +++ b/Frontalini_ecc/CompoAF/Alz&Front.lua @@ -139,7 +139,7 @@ local function CMP_Draw(bPreview) local sMsg = " " local SideNum =1 - -- **COSTRUZIONE DELLA TABELLA** + -- **COSTRUZIONE DELLA TABELLA DEI LATI DEL LATI DEL COMPONENTE** SideTab = {} local CurrSide = EgtGetFirstInGroup( Lw) local PrecSide = nil diff --git a/Frontalini_ecc/CompoAF/Triangolo3L.lua b/Frontalini_ecc/CompoAF/Triangolo3L.lua new file mode 100644 index 0000000..2670ba7 --- /dev/null +++ b/Frontalini_ecc/CompoAF/Triangolo3L.lua @@ -0,0 +1,177 @@ +-- 2015/07/08 11:45:00 +-- Triangolo dati tre lati + +-- Intestazioni +require( 'EgtBase') +_ENV = EgtProtectGlobal() +EgtEnableDebug( false) + +EgtAddToPackagePath(EgtGetSourceDir() .. 'LuaLibs\\?.lua') +require( 'EgtCompo') + +-- Valori limite +local LgMin = 10 +local AngMin = 15 + +-- Parametri : dichiarazione e valori standard +local CMP = {} +CMP.N1 = 'L1' + CMP.T1 = 3 -- 0=null, 1=bool, 2=int, 3=len, 4=num, 5=string + CMP.V1 = 650 +CMP.N2 = 'L2' + CMP.T2 = 3 + CMP.V2 = 800 +CMP.N3 = 'L3' + CMP.T3 = 3 + CMP.V3 = 736.5 +CMP.Npar = 3 +CMP.Nome = 'Triangolo3L' + +_G.CMP = CMP +-- Aggiorno con ultimi valori salvati (se presenti) +CMP.DATA = EgtGetSourceDir() .. CMP.Nome ..'.dat' +LoadCompoData() + +-- Funzione di disegno +local function CMP_Draw(bPreview) + -- Carico i messaggi + local Msg = require('EgtCompoMsg') + + -- Assegno i tre lati + local L1 = CMP.V1 + local L2 = CMP.V2 + local L3 = CMP.V3 + + -- Verifiche sui dati di input + CMP.ERR = 0 + CMP.MSG = '' + if L1 < LgMin then + L1 = LgMin + CMP.ERR = 1 + CMP.MSG = Msg[2]..GetLenLimit(LgMin) -- La lunghezza dei lati deve essere maggiore di LgMin + end + if L2 < LgMin then + L2 = LgMin + if CMP.ERR == 0 then + CMP.ERR = 2 + CMP.MSG = Msg[2]..GetLenLimit(LgMin) -- La lunghezza dei lati deve essere maggiore di LgMin + end + end + if L3 < LgMin then + L3 = LgMin + if CMP.ERR == 0 then + CMP.ERR = 3 + CMP.MSG = Msg[2]..GetLenLimit(LgMin) -- La lunghezza dei lati deve essere maggiore di LgMin + end + end + if L1 >= ( L2 + L3) then + L1 = L2 + L3 - LgMin + if CMP.ERR == 0 then + CMP.ERR = 4 + CMP.MSG = Msg[3] -- La lunghezza di un lato è troppo grande rispetto agli altri due + end + end + if L2 >= ( L1 + L3) then + L2 = L1 + L3 - LgMin + if CMP.ERR == 0 then + CMP.ERR = 5 + CMP.MSG = Msg[3] -- La lunghezza di un lato è troppo grande rispetto agli altri due + end + end + if L3 >= ( L1 + L2) then + L3 = L1 + L2 - LgMin + if CMP.ERR == 0 then + CMP.ERR = 6 + CMP.MSG = Msg[3] -- La lunghezza di un lato è troppo grande rispetto agli altri due + end + end + if not bPreview and CMP.ERR ~= 0 then + return + end + + -- Se Preview cancello tutto + if bPreview then + EgtNewFile() + EgtSetDefaultMaterial( BLACK()) + end + + -- Pezzo e Layer + local Pz = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC) -- pezzo + local Ly = EgtGroup(Pz,GDB_RT.LOC) -- layer + EgtSetName(Ly,'OutLoop') + local Lc = EgtGroup(Pz,GDB_RT.LOC) -- layer di costruzione + local Lr = EgtGroup(Pz,GDB_RT.LOC) -- layer regione + EgtSetName(Lr,'Region') + local La = EgtGroup(Pz,GDB_RT.LOC) -- layer ausiliario + EgtSetName(La,"LayAux") + local Le = EgtGroup(Pz,GDB_RT.LOC) -- layer etichette + EgtSetName(Le,"Etichette") + EgtSetCurrPartLayer(Pz,Ly) + + -- Lati del triangolo + local l2 = EgtLine(Ly,Point3d(0,0,0),Point3d(L2,0,0)) + EgtSetName(l2,"A2") + local c1 = EgtCircle(Lc,Point3d(0,0,0),L1) + local c2 = EgtCircle(Lc,Point3d(L2,0,0),L3) + local l3 = EgtLine(Ly,EgtEP(l2),EgtIP(c1,c2,Point3d(0,10,0))) + EgtSetName(l3,"A3") + local l1 = EgtLine(Ly,EgtEP(l3),EgtSP(l2)) + EgtSetName(l1,"A1") + EgtErase(Lc) + -- Riempimento del triangolo + local e1 = EgtCurveCompo(Ly,{l1,l2,l3},false) + local s1 = EgtSurfFlatRegion(Lr,e1) + if CMP.ERR == 0 then + EgtSetColor(s1,AQUA()) + else + EgtSetColor(s1,ORANGE()) + end + EgtSetAlpha(s1,25) + EgtErase(e1) + + -- Dimensioni dell'oggetto + local bbox = EgtGetBBoxGlob(Ly,GDB_BB.STANDARD) + local dimX = EgtToUiUnits(bbox:getDimX()) + local dimY = EgtToUiUnits(bbox:getDimY()) + if CMP.ERR == 0 then + CMP.MSG = Msg[1] .. EgtNumToString(dimX,2) .. ' x ' .. EgtNumToString(dimY,2) + end + + -- Dimensioni sull'oggetto + local ptP = 1 / 3 * ( EgtEP(l1,GDB_ID.ROOT) + EgtEP(l2,GDB_ID.ROOT) + EgtEP(l3,GDB_ID.ROOT)) + local sDim = EgtNumToString(dimX,2) .. ' x ' .. EgtNumToString(dimY,2) + local dDim = bbox:getRadius() * 0.1 + local dRot = 0 + if dimY > dimX then + dRot = 90 + end + local LbOn = AddLabelPnt(Lr,ptP,sDim,dDim,dRot,BLACK()) + EgtSetStatus(LbOn,GDB_ST.OFF) + + -- Etichette sulla figura + local dim = bbox:getRadius() * 0.1 + local stdoffset = 1.2 + local LblL1 = AddLabel(Le,l1,stdoffset,'L1',dim,-90,RED()) + EgtSetInfo(LblL1,"Var",1) + local LblL2 = AddLabel(Le,l2,stdoffset,'L2',dim,-90,RED()) + EgtSetInfo(LblL2,"Var",2) + local LblL3 = AddLabel(Le,l3,stdoffset,'L3',dim,-90,RED()) + EgtSetInfo(LblL3,"Var",3) + + -- Se non Preview + if not bPreview then + -- cancello le parti ausiliarie + EgtErase({La,Le}) + -- rendo visibile label sul pezzo + EgtSetStatus(LbOn,GDB_ST.ON) + 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 +end +_G.CMP_Draw = CMP_Draw