-- -- 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 -- -- Machining.lua by EgalWare s.r.l. 2016.23.05 -- Machining generation for Doors program -- 2018.11.06 V1.001 FM Check bevel profiles on top and bottom door side -- 2019.01.16 V1.002 FM fix error into FindGroupNameWithInfo -- 2019.02.08 V2.001 FM Change release to 2 by new EgtCam5 Release -- 2019.02.08 V2.002 FM Manage error in case Post processor (Machining_xx) file not defined -- 2019.07.02 V2.003 FM Add at the end, library reset commands for DoorsLib and EgtDoorsBase -- 2020.05.29 V2.004 FM Force single jambs dispsotion when material is aluminum -- 2021.07.06 V2.005 FM Manage show error messages in case the mtable info not match with corrent EgtDoor configuration -- 2021.07.06 V2.005 FM Manage show error messages in case run Dmach with empty piece or not saved piece -- 2022.07.27 V2.006 FM Modification to use compiled code -- 2024.07.24 V2.007 FM By CurrcamInfo parameter (MakeSentinelFileWhenNoMach) add to write sentinel file if there are not machining -- 2024.10.15 V2.008 FM Manage better when there is no machining on a machine to crerate a right .tok file -- 2024.11.20 V2.009 DS If Machining runs by DMACH set as current the 1st machining group -- 2025.01.17 V2.00a FM Manage .ini parameter 'OptimizeMachForLine' to enable machining adjustment for line machines -- Intestazioni require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) if not _G.DGD then _G.DGD = {} end -- Librerie particolari local sBaseDir = DGD.BASEDIR -- EgtGetSourceDir() EgtAddToPackagePath( sBaseDir .. 'LuaLibs\\?.lua') require( 'EgtDoorsBase') require( 'EgtDoorsData') local OptimizeMach = false ----------------------------------------------------------------- -- *** Sentinel write file *** ----------------------------------------------------------------- local function WriteSntFile( sFileErr, sDispMsg) if sDispMsg and #sDispMsg > 0 then local nIdFile = io.open( sFileErr, 'w') if nIdFile then nIdFile:write('\n' .. sDispMsg) nIdFile:close() end end end local function FindGroupNameWithInfo( sGroupName, sNameInfo) -- cerco il primo pezzo con il nome passato local Pz = EgtGetFirstNameInGroup( GDB_ID.ROOT, sGroupName) local Pzi = Pz local sAssemblyName local sDoorName local bNotProduce while Pz do -- verifico se la nota di produzione è per non produrre il pezzo bNotProduce = EgtGetInfo( Pz, 'Produce', 'i') == 0 -- cerco se il pezzo ha l'info desiderata sAssemblyName = EgtGetInfo( Pz, 'Assembly') if sAssemblyName and sAssemblyName == sNameInfo then if bNotProduce then return nil, nil else return Pz, sAssemblyName end elseif not sAssemblyName then -- se non ho un nome di assemblato if bNotProduce then return nil, nil end sDoorName = EgtGetInfo( Pz, 'N') end Pz = EgtGetNextName( Pz, sGroupName) end return Pz, sAssemblyName, Pzi, sDoorName end -- Librerie di lavorazione EgtAddToPackagePath( sBaseDir .. '?.lua') local EgtDoorsMsg = require( 'EgtDoorsMsg') -- variabile presentazione dialogo local bEnAssemblyDispos = false ----------------------------------------------------------------------------------- -- se machining lanciato DMACH chiedo se si vuole la generazione o la disposizione if not DGD.NCGEN then -- se dialogo abilitato if bEnAssemblyDispos then local tsMode = EgtDialogBox( ' 0 = pieces disposition, 1 = machines pieces', {'Choice:', '1'}) local sMode = '1' if tsMode then sMode = tsMode[1] end -- se scelta di disposizione pezzi if sMode == '0' then local sPathAssemb = sBaseDir .. 'LuaLibs\\' .. 'Main_Assemb_I.lua' local bOkDisp = dofile( sPathAssemb) return bOkDisp end end end -- Librerie di lavorazione EgtAddToPackagePath( sBaseDir .. 'MTables\\?.mtl') require( 'CurrDoorsCustomData') local MB = require( 'MachiningBase') -- Reset dati custom ResetDoorsCustomData() -- nome componente machining di default local sCompoMachining = 'Machining_1' -- nome file dati cam local sPathCurrMachtabOri = sBaseDir..'CurrCamInfo'..'.lua' local mCamData -- Project path, name, extension local sFilePath = EgtGetCurrFilePath() if not sFilePath then EgtOutText( EgtDoorsMsg[694]) -- se machining lanciato DMACH visualizzo errore if not DGD.NCGEN then EgtOutBox( EgtDoorsMsg[694], EgtDoorsMsg[476], EgtDoorsMsg[477]) -- Error on Nc part program generation end return false end local sFileDir, sFileName, sFileExt = EgtSplitPath( sFilePath) local sLogFile = sFileDir .. sFileName .. '.log' -- se machining lanciato DMACH if not DGD.NCGEN then -- open log file in append OpenLogFile(sLogFile, 'a') end -- --------------------------------------------------------------------------------------------- -- verifico parametro ini per gestione ottimizzazione lavorazioni macchine in linea -- --------------------------------------------------------------------------------------------- -- ottengo il file ini dell'egtcam5 local sConfigFolder = EgtGetIniFile() -- ottengo parametro local nTemp = EgtGetNumberFromIni( 'DOORS', 'OptimizeMachForLine', 0, sConfigFolder) OptimizeMach = EgtIf( nTemp > 0, true, false) -- --------------------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------------------- -- verifico se esiste il file if EgtExistsFile( sPathCurrMachtabOri) then -- utilizzo la tabella sPathCurrMachtabOri = 'CurrCamInfo' mCamData = require( sPathCurrMachtabOri) else DoorOutLog( string.format(EgtDoorsMsg[487], '', sPathCurrMachtabOri), 0) -- File non trovato EgtOutText( string.format(EgtDoorsMsg[487], '', sPathCurrMachtabOri)) -- se machining lanciato DMACH chiudo file log if not DGD.NCGEN then CloseLogFile() end return false end -- Resetto i gruppi lavorazioni se esistono local nMchId = EgtGetFirstMachGroup() while nMchId do EgtRemoveMachGroup( nMchId) nMchId = EgtGetFirstMachGroup() end local bOk = false -- nomi pezzi da cercare e nomi delle note per le porte local sPieceName = 'DOO*' local sFindNote = 'first' local MachJambTogh = 0 local nLocNumGroup -- variabile per lancio disposizione pezzi assemblato local bFirstCheckDisp = true local nIdProcessedPiece = 0 repeat -- ripeti per tutti i pezzi trovati -- determino il pezzo dell'assemblato o pezzo unico local Pz = {} local Pz2 = {} local tFoundAssembly = {} local tFoundAssembly2 = {} local sFoundAssembly local sFoundDoor local Pzi, Pii -- ricavo id pezzo e se è assemblato Pii, sFoundAssembly, Pzi, sFoundDoor = FindGroupNameWithInfo( sPieceName, sFindNote) if sFoundAssembly then table.insert( Pz, Pii) else if nIdProcessedPiece ~= Pzi then nIdProcessedPiece = Pzi table.insert( Pz, Pzi) end end table.insert( tFoundAssembly, sFoundAssembly) if #Pz > 0 then -- se il pezzo è valido if bFirstCheckDisp and bEnAssemblyDispos then local sPathAssemb = sBaseDir .. 'LuaLibs\\' .. 'Main_Assembly.lua' local MHgen = require('Main_Assembly') -- lancio funzione main del componente bOk = MHgen.main(0) -- passo il parametro per disporre l'assemblato sul piano bFirstCheckDisp = false end local MachiningsTable = EgtGetInfo( Pz[1], 'MTable') local MachiningsPath = EgtGetInfo( Pz[1], 'MTablePath') local sDoorMaterial = EgtGetInfo( Pz[1], 'Material') local bAlumDoor = FindMaterial( sDoorMaterial, 'aluminum') -- per aluminum doors -- se nome tabella non esiste esco subito if not MachiningsTable then DoorOutLog( EgtDoorsMsg[499], 0) -- Errore nel file cam EgtOutText( EgtDoorsMsg[499]) -- se machining lanciato DMACH chiudo file log if not DGD.NCGEN then CloseLogFile() end return bOk -- altrimenti controllo se esiste il file della mtable else local sMtableFile = sBaseDir .. 'MTables\\' .. MachiningsTable .. '.mtl' if not EgtExistsFile( sMtableFile) then DoorOutLog( string.format(EgtDoorsMsg[692], sMtableFile, sBaseDir), 0) -- Mtable non trovata EgtOutText( string.format(EgtDoorsMsg[692], sMtableFile, sBaseDir)) -- se machining lanciato DMACH chiudo file log if not DGD.NCGEN then EgtOutBox( string.format(EgtDoorsMsg[692], sMtableFile, sBaseDir), EgtDoorsMsg[476], EgtDoorsMsg[477]) -- Error on Nc part program generation CloseLogFile() end return bOk end -- verifico anche il percorso della Mtable se corrisponde sMtableFile = sBaseDir .. 'MTables\\' if string.lower(sMtableFile) ~= string.lower(MachiningsPath) then DoorOutLog( string.format(EgtDoorsMsg[693], sMtableFile, sBaseDir), 0) -- percorso Mtable non corrispondente EgtOutText( string.format(EgtDoorsMsg[693], sMtableFile, sBaseDir)) -- se machining lanciato DMACH chiudo file log if not DGD.NCGEN then EgtOutBox( string.format(EgtDoorsMsg[693], MachiningsPath, sMtableFile), EgtDoorsMsg[476], EgtDoorsMsg[477]) -- Error on Nc part program generation CloseLogFile() end return bOk end end local M = require( MachiningsTable) local MachinesName = M.MMachineData local MTablePrev = M.MTable local nNumMach local nNumGroup = 0 local tListCompo = {} local nNoMach -- per ogni macchina presente in MTable for j = 1, #MachinesName do -- inizializzo la variabile dei messaggi di errore if not DGD.NCGEN then DGD.ERR = nil DGD.EMC = '' DGD.ERM = '' end nNumMach = 0 MachJambTogh = 0 -- verifico se il nome macchina è presente nel file CurrCamInfo -- e se c'è il parametro per lavorare i jamb assieme for i = 1, #mCamData do if string.lower( MachinesName[j].MachName) == string.lower(mCamData[i].MachName) then nNumMach = i if mCamData[i].MachineJambsTogether then MachJambTogh = mCamData[i].MachineJambsTogether end end end -- se porta di alluminio per ora forzo la disposizione singola if bAlumDoor then MachJambTogh = 0 end -- abilitata lavorazione pezzi jamb assieme if MachJambTogh == 1 then -- se pezzo passato non è una porta cerco gli altri pezzi if sPieceName ~= 'DOO*' then -- carico tutti i pezzi frame nella tabella while sFindNote ~= '' and sFindNote ~= 'framebot' do -- se pezzo valido e non è una porta cerco il frame successivo al sinistro if sFindNote == 'framesx' then sFindNote = 'framedx' sPieceName = 'FRAME*' elseif sFindNote == 'framedx' then sFindNote = 'frametop' sPieceName = 'FRAME*' elseif sFindNote == 'frametop' then sFindNote = 'framebot' sPieceName = 'FRAME*' else sFindNote = '' end if sFindNote ~= '' and sFindNote ~= 'framebot' then Pii, sFoundAssembly, Pzi = FindGroupNameWithInfo( sPieceName, sFindNote) if Pii then table.insert( Pz, Pii) table.insert( tFoundAssembly, sFoundAssembly) end elseif sFindNote == 'framebot' then -- il frame bottom lo faccio da solo Pii, sFoundAssembly, Pzi = FindGroupNameWithInfo( sPieceName, sFindNote) if Pii then table.insert( Pz2, Pii) table.insert( tFoundAssembly2, sFoundAssembly) end end end end end if nNumMach > 0 then -- imposto i dati macchina secondo le informazioni del file cam sCompoMachining = mCamData[nNumMach].CompoMachining local MachName = mCamData[nNumMach].MachName if sCompoMachining then DoorOutLog( ' Postprocessor used: ' .. sCompoMachining, 0) -- se ci sono lavorazioni nella Mtable per la macchina selezionata entro -- MTable scanning local sLocMachId local bFoundmach = false local bFoundmach2 = false for k = 1, #MTablePrev do if MTablePrev[k].On ~= 0 then -- se non è disabilitata -- acquisisco numero macchine (se indicato), se non trovato setto macchina 1 ( per default nella Mtable) sLocMachId = MTablePrev[k].MachId or 1 if sLocMachId == j then -- se numero macchina corrispondente -- Recupero le entità local EntList = {} local EntList2 = {} local sNameMach = MTablePrev[k].Name local sNameMach2 = MTablePrev[k].Name -- se metodo assegnato è bevel verifico che siano coerenti con la dsposizione finale if MTablePrev[k].Oper and MTablePrev[k].Oper == 'AdjustBevel' then EntList = MB.FindEntitiesWithName( Pz , sNameMach) EntList2 = MB.FindEntitiesWithName( Pz2, sNameMach2) if #EntList == 0 then -- se non trovata nessuna entità provo con l'opposta local sTmpName = sNameMach sNameMach = EgtIf( sNameMach == 'BU', 'BD','BU') EntList = MB.FindEntitiesWithName( Pz, sNameMach) if #EntList == 0 then -- se non trovata nessuna entità provo con quella di testa opposta sNameMach = sTmpName sNameMach = EgtIf( sNameMach == 'BU_H', 'BD_H','BU_H') EntList = MB.FindEntitiesWithName( Pz, sNameMach) end end if #EntList2 == 0 then -- se non trovata nessuna entità provo con l'opposta local sTmpName2 = sNameMach2 sNameMach2 = EgtIf( sNameMach2 == 'BU', 'BD','BU') EntList2 = MB.FindEntitiesWithName( Pz2, sNameMach2) if #EntList2 == 0 then -- se non trovata nessuna entità provo con quella di testa opposta sNameMach2 = sTmpName2 sNameMach2 = EgtIf( sNameMach2 == 'BU_H', 'BD_H','BU_H') EntList2 = MB.FindEntitiesWithName( Pz2, sNameMach2) end end -- se non ho metodi oppure se metodo non AdjustProbeMill o non AdjustProbeHole verifico se ho lavorazioni elseif not MTablePrev[k].Oper or not ( MTablePrev[k].Oper == 'AdjustProbeMill' or MTablePrev[k].Oper == 'AdjustProbeHole') then EntList = MB.FindEntitiesWithName( Pz , sNameMach) EntList2 = MB.FindEntitiesWithName( Pz2, sNameMach2) end -- se trovate entità associate a nome lavorazione if #EntList > 0 then bFoundmach = true end if #EntList2 > 0 then bFoundmach2 = true end -- siccome sono mutuamente esclusivi perchè il frame bottom (Pz2) è lavorato da solo -- se una delle due è vera, ci sono delle lavorazioni per quel pezzo/i if bFoundmach or bFoundmach2 then break -- esco dal for appena ho trovato almeno una lavorazione end end end end if bFoundmach or bFoundmach2 then -- se ho delle lavorazioni sul pezzo/i -- metto in tabella il nome del componente lanciato per il forget table.insert( tListCompo,sCompoMachining) if nLocNumGroup and nLocNumGroup > 0 then nNumGroup = nLocNumGroup end -- lancio il primo componente base MHgen = require( sCompoMachining) if bFoundmach then bOk, nLocNumGroup, nNoMach = MHgen.Calc( Pz, tFoundAssembly, j, nNumMach, nNumGroup, OptimizeMach) end if bFoundmach2 then bOk, nLocNumGroup, nNoMach = MHgen.Calc( Pz2, tFoundAssembly2, j, nNumMach, nNumGroup, OptimizeMach) end if nNoMach == 1 then nLocNumGroup = nLocNumGroup - 1 end else nNoMach = 1 end -- se non ho lavorazioni if nNoMach == 1 then local nPieceNum = EgtIf( #Pz == 1, Pz[1], 0) if nPieceNum == 0 then nPieceNum = EgtIf( #Pz2 == 1, Pz2[1], 0) end local sPieceName = EgtIf( #tFoundAssembly == 1, tFoundAssembly[1], '') if #sPieceName < 1 then sPieceName = EgtIf( #tFoundAssembly2 == 1, tFoundAssembly2[1], '') end if #sPieceName < 1 then sPieceName = EgtIf( #sFoundDoor > 0, sFoundDoor, '') end DoorOutLog( string.format( EgtDoorsMsg[493], MachName, nPieceNum, sPieceName), 0) -- No machining for machine if not DGD.NCGEN then EgtOutBox( string.format(EgtDoorsMsg[493], MachName, nPieceNum, sPieceName), EgtDoorsMsg[501], EgtDoorsMsg[502]) end -- CurrCamInfo option to generate sentinel file local nGenSentinel = mCamData[nNumMach].MakeSentinelFileWhenNoMach or 0 if nGenSentinel == 1 then if nLocNumGroup and nLocNumGroup > 0 then nNumGroup = nLocNumGroup end -- incremento il numero del gruppo nNumGroup = nNumGroup + 1 -- compongo il file sentinella (.tok) local sNumGroup = EgtIf( nNumGroup > 1, '_' .. EgtNumToString( nNumGroup,0), '') local sSentinelFileName = sFileDir..sFileName..sNumGroup..'.tok' -- cancello il file tok EgtEraseFile( sSentinelFileName) WriteSntFile( sSentinelFileName, 'Err=0\n LIGHT=PURPLE\n \n No machining for this machine\n') end end else DoorOutLog( EgtDoorsMsg[640], 0) if not DGD.NCGEN then EgtOutBox( EgtDoorsMsg[640], EgtDoorsMsg[476], EgtDoorsMsg[477]) end end else DoorOutLog( EgtDoorsMsg[641], 0) -- Machine name mismatch if not DGD.NCGEN then EgtOutBox( EgtDoorsMsg[641], EgtDoorsMsg[476], EgtDoorsMsg[477]) end end end -- reset librerie locali package.loaded[MachiningsTable] = nil for i = 1, #tListCompo do package.loaded[tListCompo[i]] = nil end end -- effettuo la prossima ricerca if sFindNote == 'first' then sFindNote = 'second' sPieceName = 'DOO*' elseif sFindNote == 'second' then sFindNote = 'framesx' sPieceName = 'FRAME*' elseif sFindNote == 'framesx' and MachJambTogh == 0 then sFindNote = 'framedx' sPieceName = 'FRAME*' elseif sFindNote == 'framedx' and MachJambTogh == 0 then sFindNote = 'frametop' sPieceName = 'FRAME*' elseif sFindNote == 'frametop' and MachJambTogh == 0 then sFindNote = 'framebot' sPieceName = 'FRAME*' else sFindNote = '' end until sFindNote == '' -- ------------------------------------------------------------------------------------------------------------- -- ------------------------------------------------------------------------------------------------------------- -- Gestione riordino lavorazioni per macchine in linea -- ------------------------------------------------------------------------------------------------------------- -- ------------------------------------------------------------------------------------------------------------- if OptimizeMach then -- codice valutazione lavorazioni end -- ------------------------------------------------------------------------------------------------------------- -- ------------------------------------------------------------------------------------------------------------- -- reset librerie locali package.loaded.CurrCamInfo = nil package.loaded.CurrDoorsCustomData = nil -- se machining lanciato DMACH do messaggio di chiusura e rendo corrente la prima macchinata if not DGD.NCGEN then DoorOutLog( ' ' .. EgtDoorsMsg[498]..'\n', 0) EgtOutText( EgtDoorsMsg[498]) CloseLogFile() EgtSetCurrMachGroup() end -- reset librerie globali ResetDoorsLibs() package.loaded.EgtDoorsBase = nil return bOk