-- -- EEEEEEEEEE GGGGGG wwww wwww -- EEEEEEEEEE GGGGGGGGGG wwww wwww -- EEEE GGGG GGGG wwww wwww wwww -- EEEE GGGG wwww wwww wwww -- EEEEEEE GGGG GGGGGGG wwww wwwwww wwww -- EEEEEEE GGGG GGGGGGG wwww wwwwww wwww -- EEEE GGGG GGGG wwww wwwwwwww wwww -- EEEE GGGG GGGG wwww wwww wwww wwww -- EEEEEEEEEE GGGGGGGGGG wwwwwwww wwwwwwww -- EEEEEEEEEE GGGGGG wwwwwww wwwwwww -- -- MailSlot.lua by EgalWare s.r.l. 2016.07.05 -- Autore: Filippo Monchi -- Mail SLot dati i valori 'L' e 'T' e con nome attributo e dati dei fori -- 2016.07.05 V1.000 FM First version -- 2019.10.02 V1.001 FM Manage steel option (disable generation of some geometries) -- 2019.10.17 V1.002 FM Manage cut by saw and steel option (for this component it doesn't anything) -- 2019.10.18 V2.000 FM Manage use Materials -- 2020.04.29 V2.001 FM Update for aluminum material -- 2022.07.27 V2.002 FM Modification to use compiled code -- Tavola per definizione modulo (serve ma non usata) local MailSlot = {} -- Intestazioni require( 'EgtBase') EgtEnableDebug( false) -- per messaggi -- EgtAddToPackagePath( EgtGetSourceDir() .. '?.lua') EgtAddToPackagePath( DGD.BASEDIR .. '?.lua') -- Valori limite local DimMin = 4. -- valore minimo lato local function GetMachToolErrorMessage( nErrorId, sGeomName, dIdMach, dOriDiamTool, nIdLogErr, sMchngName) local EgtDoorsMsg = require( 'EgtDoorsMsg') local sMessage = '' if dOriDiamTool then if nErrorId == -1 then -- lavorazione non presente in tabella sMessage = string.format(EgtDoorsMsg[466], nIdLogErr, dIdMach, sGeomName, EgtToUiUnits( dOriDiamTool)) elseif nErrorId == -2 then -- errore nel settare la lavorazione, lavorazione non presente in libreria sMessage = string.format(EgtDoorsMsg[467], nIdLogErr, sMchngName, dIdMach, sGeomName, EgtToUiUnits( dOriDiamTool)) elseif nErrorId == -3 then -- errore nell'acquisire parametri lavorazione sMessage = string.format(EgtDoorsMsg[468], nIdLogErr, sMchngName, dIdMach, sGeomName, EgtToUiUnits( dOriDiamTool)) elseif nErrorId == -4 then -- errore nell'acquisire parametri lavorazione sMessage = string.format(EgtDoorsMsg[469], nIdLogErr, sMchngName, dIdMach, sGeomName, EgtToUiUnits( dOriDiamTool)) elseif nErrorId == -5 then -- diametro utensile non trovato sMessage = string.format(EgtDoorsMsg[470], nIdLogErr, sMchngName, dIdMach, sGeomName, EgtToUiUnits( dOriDiamTool)) elseif nErrorId == -6 then -- nome geometria non presente in tabella sMessage = string.format(EgtDoorsMsg[471], nIdLogErr, sGeomName, EgtToUiUnits( dOriDiamTool)) elseif nErrorId == -7 then -- altezza massima utensile non trovata sMessage = string.format(EgtDoorsMsg[472], nIdLogErr, sMchngName, dIdMach, sGeomName, EgtToUiUnits( dOriDiamTool)) elseif nErrorId == -8 then -- tabella non presente nelle note sMessage = string.format(EgtDoorsMsg[509], nIdLogErr) end elseif nErrorId == -1 then -- lavorazione non presente in tabella sMessage = string.format(EgtDoorsMsg[504], nIdLogErr, dIdMach, sGeomName) elseif nErrorId == -2 then -- errore nel settare la lavorazione sMessage = string.format(EgtDoorsMsg[505], nIdLogErr, sMchngName, dIdMach, sGeomName) elseif nErrorId == -3 then -- errore nell'acquisire parametri lavorazione sMessage = string.format(EgtDoorsMsg[506], nIdLogErr, sMchngName, dIdMach, sGeomName) elseif nErrorId == -4 then -- errore nell'acquisire parametri lavorazione sMessage = string.format(EgtDoorsMsg[507], nIdLogErr, sMchngName, dIdMach, sGeomName) elseif nErrorId == -5 then -- diametro utensile non trovato sMessage = string.format(EgtDoorsMsg[508], nIdLogErr, sMchngName, dIdMach, sGeomName) elseif nErrorId == -6 then -- nome geometria non presente in tabella sMessage = string.format(EgtDoorsMsg[503], nIdLogErr, sGeomName) elseif nErrorId == -7 then -- altezza massima utensile non trovata sMessage = string.format(EgtDoorsMsg[473], nIdLogErr, sMchngName, dIdMach, sGeomName) elseif nErrorId == -8 then -- tabella non presente nelle note sMessage = string.format(EgtDoorsMsg[509], nIdLogErr) end return sMessage end local function DrawAddLineDrawCircle( pInitial, pFinal, nGroup, idTable, bPrev, nGroupCirc, nRad, bDrawFirst, bDrawLast, cColor1, cColor2) local nLine = EgtLine(nGroup, pInitial, pFinal, GDB_RT.LOC) if idTable then table.insert( idTable, nLine) end if bPrev then if bDrawFirst then local nCircle1 = EgtCircle( nGroupCirc, pInitial, nRad , GDB_RT.LOC) EgtSetColor(nCircle1, cColor1) end if bDrawLast then local nCircle2 = EgtCircle( nGroupCirc, pFinal, nRad , GDB_RT.LOC) EgtSetColor(nCircle2, cColor2) end end return nLine end -- Funzione di sistemazione parametri function MailSlot.AdjustParams( tMhPar) local EgtDoorsMsg = require( 'EgtDoorsMsg') local dMaxMat0 local dNumMessage local dNumLog = 0 local sMessToOut = '' local nTempT0 local sMchngName0 local nThBl0 -- Assegno parametri da ddf if DGD.LENGTH then tMhPar.L = DGD.LENGTH end tMhPar.T = DGD.dT if tMhPar.IL then tMhPar.IL = tMhPar.IL + DGD.LENGTH end if tMhPar.DD then if tMhPar.DD == -0.5 then tMhPar.DD = DGD.dT / 2 elseif tMhPar.DD == -1 then tMhPar.DD = DGD.dT end end -- disattivo la lama se la cava è più profonda di una certa quota if tMhPar.MaxBd and tMhPar.T and tMhPar.T > tMhPar.MaxBd then tMhPar.bl = false dNumLog = -1394 dNumMessage = 674 sMessToOut = sMessToOut .. '\n'.. string.format(EgtDoorsMsg[dNumMessage], dNumLog, tMhPar.Nome, EgtToUiUnits(tMhPar.T), EgtToUiUnits(tMhPar.MaxBd)) end -- Assegno parametri da dati utensili in macchina local MB = require( 'MachiningBase') local sLBM local nLBMi = 1 local dMaxCutBladeLen = 0 -- se porta steel o aluminum if FindMaterial( DGD.Material, 'steel') or FindMaterial( DGD.Material, 'aluminum') then tMhPar.est = true else tMhPar.est = nil end if tMhPar.LBM then -- geometria con lama sLBM = tMhPar.LBM end -- se devo disegnare le geometrie di lavorazione if DGD.MachEn > 0 then if sLBM and tMhPar.bl and tMhPar.d3 then nTempT0, dMaxMat0, sMchngName0, nThBl0 = MB.GetToolDataFromAttrib( sLBM, nLBMi) end if tMhPar.d3 and nTempT0 and nTempT0 <= 0 then -- lama if DGD.bProoduce and tMhPar.bl then -- se utilizzo la lama dNumLog = -1399 sMessToOut = sMessToOut .. '\n'.. GetMachToolErrorMessage( nTempT0, sLBM, nLBMi, tMhPar.d3, dNumLog, sMchngName0) end elseif nTempT0 then tMhPar.d3 = nTempT0 if nThBl0 and nThBl0 > 0 then tMhPar.thb = nThBl0 end end -- se lo spessore porta è maggiore della capacità lama disabilito la lama ed emetto un warning if tMhPar.bl and tMhPar.T and dMaxMat0 and tMhPar.T >= dMaxMat0 then tMhPar.bl = false tMhPar.LBM = nil dNumLog = -1397 dNumMessage = 672 sMessToOut = sMessToOut .. '\n'.. string.format(EgtDoorsMsg[dNumMessage], dNumLog, tMhPar.Nome, sMchngName0, EgtToUiUnits(tMhPar.T), EgtToUiUnits(dMaxMat0)) end -- se il blade è attivo calcolo se passa la lama nella sfinestratura if tMhPar.bl and tMhPar.d3 and tMhPar.L and tMhPar.W then -- calcolo la massima impronta lama local dBladeRadius = tMhPar.d3 / 2 dMaxCutBladeLen = sqrt( (dBladeRadius * dBladeRadius) - ( ( dBladeRadius - tMhPar.T) * ( dBladeRadius - tMhPar.T))) -- se l'impronta lama è maggiore della lunghezza o larghezza escludo la lama e do messaggio di warning if (2*dMaxCutBladeLen) >= tMhPar.L or (2*dMaxCutBladeLen) >= tMhPar.W then tMhPar.bl = false tMhPar.LBM = nil dNumLog = -1395 dNumMessage = 673 sMessToOut = sMessToOut .. '\n'.. string.format(EgtDoorsMsg[dNumMessage], dNumLog, tMhPar.Nome, sMchngName0) end end -- se il blade è attivo e utensile lama e c'è il clean corner, lo ricalcolo in funzione del raggio lama if tMhPar.bl and tMhPar.thb and tMhPar.thb > 0 and tMhPar.clc and tMhPar.clc > 0 then if dMaxCutBladeLen > tMhPar.clc then tMhPar.clc = dMaxCutBladeLen end end if tMhPar.CL and tMhPar.clc and tMhPar.clc > 0 and ( tMhPar.clc >= tMhPar.W or tMhPar.clc >= tMhPar.L) then tMhPar.clc = nil elseif not tMhPar.CL then tMhPar.clc = nil end end if dNumLog ~= 0 then return tMhPar, dNumLog, sMessToOut end return tMhPar, 0, '' end -- Funzione di disegno function MailSlot.Draw( tMlSlPar, bPreview, bRunByCompo, nDrawMach) -- Assegno le dimensioni local L = tMlSlPar.L local W = tMlSlPar.W local T = tMlSlPar.T local clc = tMlSlPar.clc local ccr = tMlSlPar.ccr local bl = tMlSlPar.bl local d3 = tMlSlPar.d3 -- blade diameter local est = tMlSlPar.est -- Assegno parametri fori local ms = tMlSlPar.ms local DS = tMlSlPar.DS local DD = tMlSlPar.DD local IL = tMlSlPar.IL local IW = tMlSlPar.IW -- Assegno i nomi local LG = tMlSlPar.LG local LM = tMlSlPar.LM local SCU = tMlSlPar.SCU local CL = tMlSlPar.CL local LBM = tMlSlPar.LBM -- nome lavorazione con lama -- variabili per messaggi e settaggi vari local sCompoName = tMlSlPar.Nome local nCompoNPar = tMlSlPar.Npar local sCompoPath = tMlSlPar.Path -- eventuale messaggio errore rilevato nell'adjust local nCodAdj = tMlSlPar.nCod local sCodAdj = tMlSlPar.sCod -- variabili per messaggi e settaggi vari local sNamePar1 = tMlSlPar.N1 or 'L' local sNamePar2 = tMlSlPar.N2 or 'H' local sNamePar3 = tMlSlPar.N3 or 'T' local sNamePar4 = tMlSlPar.N4 or 'clc' local sNamePar5 = tMlSlPar.N5 or 'ccr' -- RunByComponentInterface local RC = true -- Messaggi codice errori local EM = ' ' local EC = 0 local ErrorBase = 1300 if not bRunByCompo then -- controllo se lanciato da componente RC = false end -- 0 solo geom esterna, 1 solo geom mach, 2 entrambe if not nDrawMach then -- se non definita la setto per non creare geometria di lavorazione nDrawMach = 0 end local EgtDoorsMsg = require( 'EgtDoorsMsg') -- Verifica delle dimensioni, le condizioni vengono verificate in base a quale geometria deve essere creata if L < DimMin then EC = 1 EM = string.format(EgtDoorsMsg[401],sNamePar1,EgtToUiUnits(DimMin), sCompoPath) -- il parametro 'L' deve essere > DimMin D = DimMin elseif W < DimMin then EC = 2 EM = string.format(EgtDoorsMsg[401],sNamePar2,EgtToUiUnits(DimMin), sCompoPath) -- il parametro 'H' deve essere > DimMin W = DimMin elseif CL and clc and ccr and clc > 0 and ccr > 0 and (2*(ccr*sin(45))) >= clc then EC = 3 EM = string.format(EgtDoorsMsg[407],sNamePar4,EgtToUiUnits(clc),'',EgtToUiUnits(2*(ccr*sin(45))), sCompoPath) -- il parametro 'clc' deve essere > 'crc' clc = (2*(ccr*sin(45)))+0.2 end if not bPreview and EC ~= 0 then return (ErrorBase+EC), EM end -- Se Preview cancello tutto if bPreview then EgtNewFile() EgtSetDefaultMaterial( BLACK()) end -- Pezzo e Layer local Pz if bPreview then Pz = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC) -- nuovo pezzo else if not RC then Pz = EgtGetCurrPart() -- pezzo corrente end if not Pz then Pz = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC) -- nuovo pezzo end end local Lg Lg = EgtGroup(Pz,GDB_RT.LOC) -- layer della figura principale EgtSetName(Lg,sCompoName) local GId, MId, hint_1, hint_2, hint_3, hint_4 local bSingleMode = true -- Costruzione della geometria GId = EgtRectangle2P( Lg, Point3d( -(W/2), 0, T), Point3d( (W/2), L, T), GDB_RT.GLOB) EgtModifyCurveThickness( GId, -T) EgtInvertCurve( GId) EgtSetName( GId, LG) EgtSetInfo( GId,'SideDoor','Keyway') -- setto una nota per indicare su che lato della porta deve essere spostato -- creo estrusi e superfici piane delle geometrie passanti AddSurfTmByExtrusion( Lg, GId, bSingleMode) if ms then -- se devo fare le viti if DS and DD and IL and IW then -- se dimensioni foro vite idonee if DS > 0 and DD ~= 0 then if not Lg then Lg = EgtGroup(Pz,GDB_RT.LOC) EgtSetName(Lg,sCompoName) end hint_1 = EgtCircle( Lg, Point3d( -(IW/2),-((IL-L)/2),T), DS/2 , GDB_RT.LOC) hint_2 = EgtCircle( Lg, Point3d( -(IW/2),(L+((IL-L)/2)),T), DS/2 , GDB_RT.LOC) hint_3 = EgtCircle( Lg, Point3d( (IW/2),(L+((IL-L)/2)),T), DS/2 , GDB_RT.LOC) hint_4 = EgtCircle( Lg, Point3d( (IW/2),-((IL-L)/2),T), DS/2 , GDB_RT.LOC) EgtModifyCurveThickness(hint_1, -DD) EgtModifyCurveThickness(hint_2, -DD) EgtModifyCurveThickness(hint_3, -DD) EgtModifyCurveThickness(hint_4, -DD) EgtSetName(hint_1,SCU) EgtSetName(hint_2,SCU) EgtSetName(hint_3,SCU) EgtSetName(hint_4,SCU) EgtSetInfo(hint_1,'SideDoor','Keyway') -- setto una nota per indicare su che lato della porta deve essere spostato EgtSetInfo(hint_2,'SideDoor','Keyway') -- setto una nota per indicare su che lato della porta deve essere spostato EgtSetInfo(hint_3,'SideDoor','Keyway') -- setto una nota per indicare su che lato della porta deve essere spostato EgtSetInfo(hint_4,'SideDoor','Keyway') -- setto una nota per indicare su che lato della porta deve essere spostato -- creo estrusi e superfici piane delle geometrie passanti AddSurfTmByExtrusion( Lg, hint_1, bSingleMode) AddSurfTmByExtrusion( Lg, hint_2, bSingleMode) AddSurfTmByExtrusion( Lg, hint_3, bSingleMode) AddSurfTmByExtrusion( Lg, hint_4, bSingleMode) end end end -- Costruzione della geometria clean corner if nDrawMach >= 0 then -- se abilitata geometria -- se ci sono i parametri per i percorsi clean corner if CL and clc and clc > 0 and clc < W and clc < L then -- angolo x-y+ local CLC1 = MakeClcPath( clc, ccr, CL, Lg, -T) EgtMove( CLC1, Point3d(-(W/2),L,T) - ORIG()) -- angolo x+y+ local CLC2 = EgtCopyGlob( CLC1, Lg) EgtRotate( CLC2, Point3d(-(W/2),L,0), Z_AX(), -90) EgtMove( CLC2, Point3d(W,0,0) - ORIG()) -- angolo x+y- CLC2 = EgtCopyGlob( CLC1, Lg) EgtRotate( CLC2, Point3d(-(W/2),L,0), Z_AX(), 180) EgtMove( CLC2, Point3d(W,-L,0) - ORIG()) -- angolo x-y- CLC2 = EgtCopyGlob( CLC1, Lg) EgtRotate( CLC2, Point3d(-(W/2),L,0), Z_AX(), 90) EgtMove( CLC2, Point3d(0,-L,0) - ORIG()) end end -- Costruzione della geometria di lavorazione if nDrawMach > 0 then -- se abilitata geometria lavorazione -- Costruzione della geometria MId = EgtRectangle2P( Lg, Point3d( -(W/2), 0, T), Point3d( (W/2), L, T), GDB_RT.GLOB) EgtChangeClosedCurveStartPoint( MId, Point3d( 0, 0, T), GDB_RT.GLOB) EgtModifyCurveThickness( MId, -T) EgtInvertCurve( MId) if bl then EgtSetName( MId, LBM) EgtSetInfo( MId, 'ByBlade', bl) else EgtSetName( MId, LM) end EgtSetInfo( MId,'SideDoor','Keyway') -- setto una nota per indicare su che lato della porta deve essere spostato end -- cambio colore alla geometria if bPreview then if EC == 0 then if GId then EgtSetColor( GId or GDB_ID.NULL, AQUA()) end if MId then EgtSetColor( MId or GDB_ID.NULL, AQUA()) end if hint_1 then EgtSetColor( hint_1 or GDB_ID.NULL, AQUA()) end if hint_2 then EgtSetColor( hint_2 or GDB_ID.NULL, AQUA()) end if hint_3 then EgtSetColor( hint_3 or GDB_ID.NULL, AQUA()) end if hint_4 then EgtSetColor( hint_4 or GDB_ID.NULL, AQUA()) end else if GId then EgtSetColor( GId or GDB_ID.NULL, ORANGE()) end if MId then EgtSetColor( MId or GDB_ID.NULL, ORANGE()) end if hint_1 then EgtSetColor( hint_1 or GDB_ID.NULL, ORANGE()) end if hint_2 then EgtSetColor( hint_2 or GDB_ID.NULL, ORANGE()) end if hint_3 then EgtSetColor( hint_3 or GDB_ID.NULL, ORANGE()) end if hint_4 then EgtSetColor( hint_4 or GDB_ID.NULL, ORANGE()) end end end -- Se non Preview -- (NOTA : se ci sono errori il componente non viene eseguito dal programma di gestione dei componenti) if not bPreview then if bRunByCompo then -- scrivo i parametri nelle info del pezzo WriteCompoDataToPart(Pz,sCompoName,nCompoNPar) end -- scrivo note nel layer della cerniera EgtSetInfo(Lg,'Type' ,'MailSlot') EgtSetInfo(Lg,'L' ,L) EgtSetInfo(Lg,'H' ,H) EgtSetInfo(Lg,'T' ,T) EgtSetInfo(Lg,'ms' ,ms) EgtSetInfo(Lg,'clc' ,clc) EgtSetInfo(Lg,'ccr' ,ccr) EgtSetInfo(Lg,'bl' ,bl) EgtSetInfo(Lg,'d3' ,d3) EgtSetInfo(Lg,'est' ,est) EgtSetInfo(Lg,'DS' ,DS) EgtSetInfo(Lg,'DD' ,DD) EgtSetInfo(Lg,'IL' ,IL) EgtSetInfo(Lg,'IW' ,IW) EgtSetInfo(Lg,'LG' ,LG) EgtSetInfo(Lg,'LM' ,LM) EgtSetInfo(Lg,'SCU' ,SCU) EgtSetInfo(Lg,'LBM' ,LBM) EgtSetInfo(Lg,'Path' ,sCompoPath) end if EC == 0 and nCodAdj and nCodAdj < 0 then EC = nCodAdj EM = sCodAdj end return EC, EM, Lg end return MailSlot