-- EgtCompo.lua by EgalTech s.r.l. 2020/02/08 -- Tavola per definizione modulo (serve ma non usata) local EgtCompo = {} print( 'EgtCompo started') -- 2021/07 -- Disegna un rattangolo dati layer, Punto, base, altezza e versore (direzione) della base -- e con opzione per esploderlo o meno function DrawRect (Lay, Pt, Blength, HLength, Vect, sName) local l1 = EgtLinePVL(Lay,Pt,Vect,Blength) EgtSetName(l1,sName.."l1") end -- Restituisce l'angolo interno di due lati consecutivi di un poligono function GetAngIntPol (l1,l2) local v1 =EgtSV(l1) local v2= EgtSV(l2) local AngEst =atan2((v1^v2)*Z_AX(),v1*v2) return 180 - AngEst end -- -- Evidenzia un angolo di un poligono -- function ColAngIntPol (l1,l2) -- -local v1 =EgtSV(l1) -- -local v2= EgtSV(l2) -- -local arc , rref -- -rref = min(L2,L3)/3 -- -arc = EgtArcC2P(La,EgtEP(l2),Point3d(L2-rref,0,0),EgtEP(l3)) -- end -- Restituisce un vettore ( o versore ) ruotato dell'angola dato function VRotated( Vect, AngRot) local CVect = Vector3d( Vect) CVect:rotate( Z_AX(), AngRot) return CVect end -- Aggiunge i trattini perpendicolari alle estremità della linea function AddLineDashes( Lq, LineId, dLen) local ptS = EgtSP( LineId, Lq) local ptE = EgtEP( LineId, Lq) local vtDir = EgtSV( LineId, Lq) vtDir:rotate( Z_AX(), 90) EgtLinePVL( Lq, ptS - vtDir * dLen / 2, vtDir, dLen) EgtLinePVL( Lq, ptE - vtDir * dLen / 2, vtDir, dLen) end -- Aggiunge un simbolo circolare all'angolo dati due lati function CircleIntPol (Layer,l1,l2,Ang,cnv) -- cnv = true se angolo dato acuto --ErrArc = EgtArcC2P(La,EgtSP(l2),Point3d(20,0,0),EgtSP(l1)) local vtBis, dLen, ptAngErr, crAngErr, sfAngErr if cnv then vtBis = EgtSV(l2)-EgtEV(l1) else vtBis = -( EgtSV(l2)-EgtEV(l1)) end vtBis:normalize() dLen = 10 / sin( 0.5 * Ang) ptAngErr = EgtSP(l2) + vtBis * dLen + Vector3d(0,0,10) crAngErr = EgtCircle(Layer,ptAngErr,7.5) sfAngErr = EgtSurfTmByFlatContour(Layer,crAngErr,7.5) EgtSetColor({crAngErr,sfAngErr},ORANGE()) end -- Restituisce la stringa del valore limite con le unità di misura UI function GetLenLimit(Lim) if EgtUiUnitsAreMM() then return EgtNumToString(Lim,2)..' mm' else return EgtNumToString(EgtToUiUnits(Lim)+0.01,2)..' in' end end -- Inserisce una etichetta orizzontale centrata nel punto indicato function AddLabelPnt(Lay,pt,sText,dH,Rot,col) local v = EgtTextAdv(Lay,pt,Rot,sText,'',100,'S',dH,1,0,GDB_TI.MC,GDB_RT.GLOB) EgtSetColor(v,col) return v end -- Inserisce una etichetta orizzontale vicino al punto medio di un elemento function AddLabel(Lay,nEdge,offset,sText,dH,rot,col) local vt = EgtMV(nEdge,GDB_ID.ROOT) vt:rotate(Z_AX(),rot) -- rot=rotazione del versore di offset local pt = EgtMP(nEdge,GDB_ID.ROOT) + vt * offset * dH + Vector3d(0,0,10) local v = EgtTextAdv(Lay,pt,0,sText,'',100,'S',dH,1,0,GDB_TI.MC,GDB_RT.GLOB) EgtSetColor(v,col) EgtSetStatus(v,GDB_ST.SEL) return v end -- Inserisce una etichetta allineata vicino al punto medio di un elemento function AddLabelAl(Lay,nEdge,offset,sText,dH,rot,col) local vt = EgtMV(nEdge,GDB_ID.ROOT) local vtAng = atan2(vt:getY(),vt:getX()) vt:rotate(Z_AX(),rot) -- rot=rotazione del versore di offset local pt = EgtMP(nEdge,GDB_ID.ROOT) + vt * offset * dH + Vector3d(0,0,10) local v = EgtTextAdv(Lay,pt,vtAng,sText,'',100,'S',dH,1,0,GDB_TI.MC,GDB_RT.GLOB) EgtSetColor(v,col) EgtSetStatus(v,GDB_ST.SEL) return v end -- Inserisce una etichetta orizzontale vicino alla posizione data (para. "U" da sx) di un elemento function AddLabelU(Lay,nEdge,U,offset,sText,dH,rot,col) --local vt = EgtMV(nEdge-1,GDB_ID.ROOT) local vt = EgtMV(nEdge,GDB_ID.ROOT) vt:rotate(Z_AX(),rot) -- rot=rotazione del versore di offset local pt = EgtUP(nEdge,U,GDB_ID.ROOT) + vt * offset * dH + Vector3d(0,0,10) local v = EgtTextAdv(Lay,pt,0,sText,'',100,'S',dH,1,0,GDB_TI.MC,GDB_RT.GLOB) EgtSetColor(v,col) EgtSetStatus(v,GDB_ST.SEL) return v end -- Inserisce una etichetta allineata vicino alla posizione data (para. "U" da sx) di un elemento function AddLabelUAl(Lay,nEdge,U,offset,sText,dH,rot,col) local vt = EgtMV(nEdge,GDB_ID.ROOT) --local vt = EgtMV(nEdge,GDB_ID.ROOT) local vtAng = atan2(vt:getY(),vt:getX()) vt:rotate(Z_AX(),rot) -- rot=rotazione del versore di offset local pt = EgtUP(nEdge,U,GDB_ID.ROOT) + vt * offset * dH + Vector3d(0,0,10) local v = EgtTextAdv(Lay,pt,vtAng,sText,'',100,'S',dH,1,0,GDB_TI.MC,GDB_RT.GLOB) EgtSetColor(v,col) EgtSetStatus(v,GDB_ST.SEL) return v end -- Carica i dati del componente dal file opportuno function LoadCompoData() pcall(dofile,CMP.DATA) end -- Salva i dati del componente nel file opportuno function SaveCompoData(NumVar) local fh = io.open( CMP.DATA, 'w') if not fh then return end for i = 1, NumVar do local Tx = 'T' .. tostring(i) local Vx = 'V' .. tostring(i) if CMP[Tx] ~= 5 then fh:write( 'CMP.'..Vx..'='..tostring(CMP[Vx])..'\n') else fh:write( 'CMP.'..Vx..'='..string.format("%q",CMP[Vx])..'\n') end end io.close( fh) end -- Scrivo i parametri nelle info del pezzo function WriteCompoDataToPart( Pz, CmpName, NumVar) -- nome del componente EgtSetInfo(Pz,'CMP',CmpName) -- parametri for i = 1, NumVar do local Vx = 'V' .. tostring(i) EgtSetInfo( Pz, Vx, tostring( CMP[Vx])) end end -- Cancello un buco (porta o finestra) dalla parete function RemoveHole( nInd) -- Verifico che mi sia stato passato un buco definito if nInd < 1 then return end -- Recupero il pezzo local Pz = EgtGetFirstGroupInGroup( GDB_ID.ROOT) if not Pz then EgtOutLog( 'RemoveHole : Part layer not found') return end -- Recupero il layer ausiliario local Ly = EgtGetFirstNameInGroup( Pz, "LayAux") if not Ly then EgtOutLog( 'RemoveHole : Aux layer not found') return end -- Recupero il layer outloop local Lw = EgtGetFirstNameInGroup( Pz, "OutLoop") if not Lw then EgtOutLog( 'RemoveHole : Outline layer not found') return end -- Recupero il layer della superficie dei buchi local La = EgtGetFirstNameInGroup( Pz, "SelectRegion") if not La then EgtOutLog( 'RemoveHole : SelectRegion not found') return end -- Recupero il layer della superficie del piano local Lo = EgtGetFirstNameInGroup( Pz, "Region") if not Lo then EgtOutLog( 'RemoveHole : Region not found') return end -- Cerco il layer del buco local Li = EgtGetFirstNameInGroup( Pz, "InLoop") while Li do local Temp = EgtGetInfo( Li, "ID", 'i') if Temp == nInd then break end Li = EgtGetNextName( Li, "InLoop") end -- Se non trovato, cerco il layer del foro da sotto if not Li then Li = EgtGetFirstNameInGroup( Pz, "UnderDrill") while Li do local Temp = EgtGetInfo( Li, "ID", 'i') if Temp == nInd then break end Li = EgtGetNextName( Li, "UnderDrill") end end -- Se non trovato, cerco il layer del ribasso if not Li then Li = EgtGetFirstNameInGroup( Pz, "Pocket") while Li do local Temp = EgtGetInfo( Li, "ID", 'i') if Temp == nInd then break end Li = EgtGetNextName( Li, "Pocket") end end -- Se non trovato, cerco il layer delle righe if not Li then Li = EgtGetFirstNameInGroup( Pz, "OnPath") while Li do local Temp = EgtGetInfo( Li, "ID", 'i') if Temp == nInd then break end Li = EgtGetNextName( Li, "OnPath") end end -- prima di procedere elimino tutti i possibili riferimenti a questo oggetto RemoveReferences( Li) -- Recupero il layer delle etichette del buco local Ll = EgtGetFirstNameInGroup( Pz, "HoleLabels") while Ll do local Temp = tonumber(EgtGetInfo( Ll, "ID")) if Temp == nInd then break end Ll = EgtGetNextName( Ll, "HoleLabels") end if not Lw then EgtOutLog( 'RemoveHole : Loops layer not found') return end -- Cancello il riempimento del vuoto con i dati del CMP local sInd = tostring( nInd) local v0 = EgtGetFirstNameInGroup( La, sInd) if v0 then EgtErase( v0) end -- Cancello il loop del vuoto EgtErase( Li) EgtErase( Ll) -- Ricalcolo della regione CreateTopSurf( Lw, Lo, Ly, La) end function RemoveReferences( Li) if not Li then return end local IndexRef = 1 local Key = "refInd"..tostring( IndexRef) local info = EgtGetInfo( Li, Key, 'i') while info do RemoveHole( info) IndexRef = IndexRef + 1 Key = "refInd"..tostring( IndexRef) info = EgtGetInfo( Li, Key, 'i') end Key = "refInd_Pocket" info = EgtGetInfo( Li, Key, 'i') local Pz = EgtGetParent( Li) local ref_Li = EgtGetFirstNameInGroup( Pz, "Pocket") while ref_Li do local Temp = EgtGetInfo( ref_Li, "ID", 'i') if Temp == info then local I = 1 local K = "refInd"..tostring( I) local R = EgtGetInfo( ref_Li, K, 'i') while R and R ~= EgtGetInfo( Li, "ID", 'i') do I = I + 1 K = "refInd"..tostring( I) R = EgtGetInfo( ref_Li, K, 'i') end EgtSetInfo( ref_Li, K, 0) break end ref_Li = EgtGetNextName( ref_Li, "Pocket") end return end -- Crea la superficie di un top bucato function CreateTopSurf( Lw, Lo, Ly, Ls) -- Cancello vecchia superficie local Id = EgtGetFirstInGroup( Lo) while Id do if EgtGetType(Id) == GDB_TY.SRF_FRGN then local EraseId = Id Id = EgtGetNext( Id) EgtErase( EraseId) else Id = EgtGetNext( Id) end end -- Cerco il contorno della parete (sempre 0) e ne creo la faccia local list = {} local e0 = EgtGetFirstInGroup(Lw) while e0 do table.insert(list,e0) e0=EgtGetNext(e0) end e0 = EgtCurveCompo(Ly,list,false) if not e0 then return false end local s0 = EgtSurfFlatRegion(Lo,e0) EgtSetColor(s0,AQUA()) EgtSetAlpha(s0,25) EgtErase(e0) -- cerco eventuali buchi (porte o finestre da 1 in su) local e1 = EgtGetFirstInGroup(Ls) while e1 do if EgtGetName(e1) ~= "0" then local nNoTrim = EgtGetInfo( e1, "NoTrim", 'i') if not nNoTrim or nNoTrim ~= 1 then EgtSurfFrSubtract( s0, e1) end end e1 = EgtGetNext(e1) end return true end -- di CreateTopSurf(Lw,Lo,Ly,Ls) return EgtCompo