Files
3dprinting/LuaLibs/RunMachiningParamCalc.lua
T
SaraP ddc72269fc 3dPrinting :
- modifiche per nuova interfaccia.
2022-08-26 16:19:53 +02:00

199 lines
7.9 KiB
Lua

-- RunMachiningParamCalc.lua by Egaltech s.r.l. 2022/04/13
-- Gestione visualizzazione per Stampa 3d
-- Tabella per definizione modulo
local RunMachiningParamCalc = {}
-- Intestazioni
require( 'EgtBase')
EgtOutLog( ' RunMachiningParamCalc started', 1)
-- Costanti generali
local AMD = require( 'AddManData')
local CSV = require( 'CSVManager')
---------------------------------------------------------------------
function RunMachiningParamCalc.Exec()
-- Dati recuperati dalla macchina
local sMachIni = EgtGetCurrMachineDir() .. '\\' .. EgtGetCurrMachineName() .. '.ini'
local dCoeffX = tonumber( EgtGetStringFromIni( SEC_3DPRINTING, KEY_COEFF_X, 0, sMachIni))
local dCoeffY = tonumber( EgtGetStringFromIni( SEC_3DPRINTING, KEY_COEFF_Y, 0, sMachIni))
-- File dei risultati
local sCalcBaseDir = EgtGetStringFromIni( '3dPrinting', 'BaseDir', 'C:\\ProgramData\\Egaltech\\EgtCam5\\3dPrinting', EgtGetIniFile())
local sCurrProjectPath = EgtGetCurrFilePath()
local sResultFile = EgtChangePathExtension( sCurrProjectPath, '.csv')
local bResultFile = EgtExistsFile( sResultFile)
-- carico eventuale file dei risultati
local CSVOldResult
if bResultFile then
CSVOldResult = read_file( sResultFile)
end
-- tabella del csv del risultato
local CSVNewResult = {}
-- ciclo sui pezzi
local nPartId = EgtGetFirstPart()
while nPartId do
if not EgtGetInfo( nPartId, KEY_PART_ON_TABLE, 'b') then
nPartId = EgtGetNextPart( nPartId)
goto continue
end
-- recupero i parametri di lavorazione del pezzo
local dMachiningFeed = EgtGetInfo( nPartId, KEY_FEED, 'd')
local dSliceStep = EgtGetInfo( nPartId, KEY_SLICE_STEP, 'd')
local dStrand = EgtGetInfo( nPartId, KEY_STRAND, 'd')
local sMaterial = EgtGetInfo( nPartId, KEY_MATERIAL)
-- verifico la definizione dei parametri
if not dMachiningFeed then
EgtOutBox( 'Impossible calculating before applying a machining.', 'Error', 'ERROR')
return
end
-- calcolo intervallo tempi consentito
local sMaterialPath = sCalcBaseDir .. '\\Materials\\' .. sMaterial .. '.csv'
local MaterialCSV = read_file( sMaterialPath)
local dMinTime = 0
local dMaxTime = 0
if not MaterialCSV then
EgtOutBox( 'Material csv file not found.', 'Error', 'ERROR')
return
end
local bSectionFound = false
for nSectionIndex = 1, #MaterialCSV do
local Section = MaterialCSV[nSectionIndex]
if tonumber( Section[1]) == dStrand and tonumber( Section[2]) == dSliceStep then
dMinTime = tonumber(Section[3])
dMaxTime = tonumber(Section[4])
bSectionFound = true
break
end
end
if not bSectionFound then
EgtOutBox( 'Section not found in Material csv file.', 'Error', 'ERROR')
return
end
-- ciclo sui layer
local nLayerIndex = 1
local nLayerId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .. nLayerIndex)
while nLayerId do
local sLayerName = EgtGetName( nLayerId)
local nLayerIndex = tonumber( sLayerName:sub( #SLICE_LAYER + 1))
-- rimuovo eventuale info precedente del tempo di attesa
EgtRemoveInfo( nLayerId, KEY_WAITING_TIME)
-- calcolo lunghezza totale del layer
local dTotLayerLength = 0
local nCrvId = EgtGetFirstGroupInGroup( nLayerId)
while nCrvId do
local nToolPathId = EgtGetFirstNameInGroup( nCrvId, TOOLPATH_GRP)
-- sommo lunghezze percorsi
local dTotCrvLength = 0
nShellId = EgtGetFirstInGroup( nToolPathId)
while nShellId do
--local nType = EgtGetInfo( nShellId, KEY_TYPE, 'i')
dTotCrvLength = dTotCrvLength + EgtCurveLength( nShellId)
nShellId = EgtGetNext( nShellId)
end
dTotLayerLength = dTotLayerLength + dTotCrvLength
nCrvId = EgtGetNext( nCrvId)
end
-- recupero feed del layer
local dLayerFeed = 0
if bResultFile then
-- leggo il valore dal file
local bResultFound = false
for nResultIndex = 1, #CSVOldResult do
local OldResult = CSVOldResult[nResultIndex]
if tonumber( OldResult[1]) == nLayerIndex then
dLayerFeed = tonumber( OldResult[5])
bResultFound = true
break
end
end
if not bResultFound then
-- uso valore di default
dLayerFeed = dMachiningFeed
end
else
-- uso valore di default
dLayerFeed = dMachiningFeed
end
-- calcolo tempo stimato del layer
local dEsteemedTime = dTotLayerLength / dLayerFeed * 60
-- calcolo speed
local dSpeed = ((( dLayerFeed * dSliceStep * dStrand ) / 60) - dCoeffX) / dCoeffY
-- scrivo info feed e speed in group toolpath
nCrvId = EgtGetFirstNameInGroup( nLayerId, CONTOUR_GRP .. '*')
while nCrvId do
local nToolPathId = EgtGetFirstNameInGroup( nCrvId, TOOLPATH_GRP)
EgtSetInfo( nToolPathId, KEY_FEED, dLayerFeed)
EgtSetInfo( nToolPathId, KEY_SPEED, dSpeed)
nCrvId = EgtGetNextName( nCrvId, CONTOUR_GRP .. '*')
end
-- salvo e riporto valori calcolati in tabella per csv
local sStatus = ''
if dEsteemedTime < dMinTime then
EgtSetInfo( nLayerId, KEY_RESULT, RESULT.KO_MINUS)
EgtSetInfo( nLayerId, KEY_WAITING_TIME, dMinTime - dEsteemedTime)
sStatus = 'KO(-)'
elseif dEsteemedTime > dMinTime and dEsteemedTime < dMaxTime then
EgtSetInfo( nLayerId, KEY_RESULT, RESULT.OK)
sStatus = 'OK'
elseif dEsteemedTime > dMaxTime then
EgtSetInfo( nLayerId, KEY_RESULT, RESULT.KO_PLUS)
sStatus = 'KO(+)'
end
--table.insert( CSVOutTable, { Index = nLayerIndex, EsteemedTime = dEsteemedTime, Feed = dLayerFeed, Speed = dSpeed})
table.insert( CSVNewResult, { nLayerIndex, dTotLayerLength, dEsteemedTime, sStatus, dLayerFeed, dSpeed})
nLayerIndex = nLayerIndex + 1
nLayerId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .. nLayerIndex)
end
nPartId = EgtGetNextPart( nPartId)
::continue::
end
-- aggiorno palette
local nViewId = EgtGetFirstNameInGroup( GDB_ID.ROOT, VIEWPARAMS)
local nPaletteType = EgtGetInfo( nViewId, KEY_PALETTE, 'i')
if nPaletteType == PALETTE_TYPE.RESULTS then
local RSP = require( 'RunSlicePalette')
RSP.UpdateColors( nPaletteType)
end
-- scrivo nuovo file csv di risultato
local file = io.open( sResultFile, "w")
if file then
file:write('LayerIndex; Len; Time; Status; Feed; Speed')
file:write('\n')
for NewResultIndex = 1, #CSVNewResult do
local CSVOutLine = CSVNewResult[NewResultIndex]
local sParams = ''
for ParamIndex = 1, #CSVOutLine do
if ParamIndex > 1 then
sParams = sParams .. ";"
end
if ParamIndex == 4 then
sParams = sParams .. CSVOutLine[ParamIndex]
else
sParams = sParams .. EgtNumToString( CSVOutLine[ParamIndex], 1)
end
end
file:write(sParams)
file:write('\n')
end
file:close()
local sReadProgPath = EgtGetStringFromIni( '3dPrinting', RESULT_READ_PROG, "", EgtGetIniFile())
if not sReadProgPath or not EgtWinExec( '"'..sReadProgPath..'" "'..sResultFile..'"') then
EgtOutBox( 'Impossible opening software to show results. You can find them in ' .. sResultFile, 'Error', 'ERROR')
end
else
EgtOutBox( 'Impossible writing results file in ' .. sResultFile, 'Error', 'ERROR')
end
end
---------------------------------------------------------------------
return RunMachiningParamCalc