-- 2015/07/__ -- Rettangolo dati base e altezza -- Intestazioni require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) EgtAddToPackagePath(EgtGetSourceDir() .. 'LuaLibs\\?.lua') require( 'EgtCompo') -- Valori limite local LgMin = 10 -- Parametri : dichiarazione e valori standard local CMP = {} CMP.N1 = 'L' CMP.T1 = 3 -- 0=null, 1=bool, 2=int, 3=len, 4=num, 5=string CMP.V1 = 300. CMP.N2 = 'H' CMP.T2 = 3 CMP.V2 = 400. CMP.Npar = 2 CMP.Nome = 'Rettangolo' CMP.INFO = nil CMP.WithTop = true _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 le dimensioni local L = CMP.V1 local H = CMP.V2 CMP.ERR = 0 CMP.MSG = '' -- Verifica della dimensioni if L < LgMin then L = LgMin CMP.ERR = 1 CMP.MSG = Msg[2]..GetLenLimit(LgMin) -- La lunghezza dei lati deve essere maggiore di elseif H < LgMin then H = LgMin CMP.ERR = 2 CMP.MSG = Msg[2]..GetLenLimit(LgMin) -- La lunghezza dei lati deve essere maggiore di 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 della figura principale EgtSetName(Ly,'OutLoop') local Lr = EgtGroup(Pz,GDB_RT.LOC) -- layer regione EgtSetName(Lr,'Region') local Lc = EgtGroup(Pz,GDB_RT.LOC) -- layer di costruzione local La = EgtGroup(Pz,GDB_RT.LOC) -- layer ausiliario (diagonali ausiliarie e relative etichette, assi) EgtSetName(La,"LayAux") local Le = EgtGroup(Pz,GDB_RT.LOC) -- layer delle etichette pezzo EgtSetName(Le,"Etichette") local Lq = EgtGroup(Pz,GDB_RT.LOC) -- layer delle linee di quotatura EgtSetName(Lq,"Quotature") EgtSetCurrPartLayer(Pz,Ly) -- Costruzione della figura: lati local l1 = EgtLine(Ly,Point3d(0,0,0),Point3d(L,0,0)) EgtSetName(l1,"A1") local l2 = EgtLine(Ly,EgtEP(l1),Point3d(L,H,0)) EgtSetName(l2,"A2") local l3 = EgtLine(Ly,EgtEP(l2),Point3d(0,H,0)) EgtSetName(l3,"A3") local l4 = EgtLine(Ly,EgtEP(l3),EgtSP(l1)) EgtSetName(l4,"A4") -- assi local a1 = EgtLinePDL(La,EgtMP(l2),180,L) local a2 = EgtLinePDL(La,EgtMP(l3),-90,H) local d1, D1 if CMP.ERR == 0 then d1 = EgtLine(La,EgtSP(l1),EgtSP(l3)) D1 = (EgtCurveLength(d1)) end -- Riempimento del rettangolo local e1 = EgtCurveCompo(Ly,{l1,l2,l3,l4},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()) local dim = bbox:getRadius() * 0.1 local pVal= bbox:getMin() - Vector3d(0,dim*2.8,0) if CMP.ERR == 0 then CMP.MSG = Msg[1] .. EgtNumToString(dimX,2) .. ' x ' .. EgtNumToString(dimY,2) end -- Dimensioni sull'oggetto local ptP = 0.5 * ( bbox:getMin() + bbox:getMax()) local sDim = '' if CMP.INFO then sDim = sDim .. CMP.INFO if ( min( dimX, dimY) / max( dimX, dimY)) > 0.3 then sDim = sDim .. '
' else sDim = sDim .. ' ' end end sDim = 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 fgure local stdoffset = 1.2 --local sL = CMP.N1 .. '=' .. EgtNumToString(EgtToUiUnits(L),2) local sL = CMP.N1 local v1 = AddLabel(Le,l1,stdoffset,sL,dim,-90,RED()) EgtSetInfo(v1,"Var",1) --local sH = CMP.N2 .. '=' .. EgtNumToString(EgtToUiUnits(H),2) local sH = CMP.N2 local v2 = AddLabel(Le,l2,stdoffset,sH,dim,-90,RED()) EgtSetInfo(v2,"Var",2) if CMP.ERR == 0 then local LblD1 = AddLabelAl(La,d1,stdoffset*.75,'D',dim*.5,90,GREEN()) end -- Etichette sotto la figura if CMP.ERR == 0 then local lLenD1 = EgtToUiUnits(D1) local sLenD1 = EgtNumToString(lLenD1,1) local ValD1 = EgtTextAdv(La,pVal,0,'D='..sLenD1,'',100,'S',dim*.5,1,0,GDB_TI.BL) EgtSetColor(ValD1,GREEN()) EgtSetStatus(ValD1,GDB_ST.SEL) local dD1Len = (EgtEP(ValD1)-EgtSP(ValD1)):getX() + dim/2 pVal = pVal + Vector3d(dD1Len,0,0) end -- Se non Preview if not bPreview then -- cancello le parti ausiliarie EgtErase({La,Le,Lc,Lq}) -- rendo visibile label sul pezzo EgtSetStatus(LbOn,GDB_ST.ON) end -- Se non ci sono errori 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 return end _G.CMP_Draw = CMP_Draw CMP_Draw(true) EgtZoom(SCE_ZM.ALL)