- Modificate tutti i lua dei bottoni per portarli in libreria
This commit is contained in:
+5
-164
@@ -10,168 +10,9 @@ EgtEnableDebug( false)
|
||||
local sBaseDir = EgtGetSourceDir()
|
||||
EgtAddToPackagePath( sBaseDir .. 'LuaLibs\\?.lua')
|
||||
|
||||
-- Costanti generali
|
||||
local AMD = require( 'AddManData')
|
||||
local CSV = require( 'CSVManager')
|
||||
-- Librerie
|
||||
_G.package.loaded.RunMachiningParamCalc = nil
|
||||
local RMPC = require( 'RunMachiningParamCalc')
|
||||
|
||||
nParamsGrp = EgtGetFirstNameInGroup( GDB_ID.ROOT, PARAMS_GRP) or GDB_ID.NULL
|
||||
if nParamsGrp == GDB_ID.NULL then
|
||||
EgtOutBox( 'Impossible calculating before applying a machining.', 'Error', 'ERROR')
|
||||
return
|
||||
end
|
||||
|
||||
local dMachiningFeed = EgtGetInfo( nParamsGrp, KEY_FEED, 'd')
|
||||
local dSliceStep = EgtGetInfo( nParamsGrp, KEY_SLICE_STEP, 'd')
|
||||
local dStrand = EgtGetInfo( nParamsGrp, KEY_STRAND, 'd')
|
||||
local sMaterial = EgtGetInfo( nParamsGrp, KEY_MATERIAL)
|
||||
|
||||
local sMachiningPath = EgtGetStringFromIni( '3dPrinting', 'ParamFile', "", EgtGetIniFile())
|
||||
local dCoeffX = tonumber( EgtGetStringFromIni( DEFAULT_SECTION, KEY_COEFF_X, 0, sMachiningPath))
|
||||
local dCoeffY = tonumber( EgtGetStringFromIni( DEFAULT_SECTION, KEY_COEFF_Y, 0, sMachiningPath))
|
||||
local sCalcBaseDir = EgtGetStringFromIni( '3dPrinting', 'BaseDir', 'C:\\ProgramData\\Egaltech\\EgtCam5\\3dPrinting', EgtGetIniFile())
|
||||
local sCurrProjectPath = EgtGetCurrFilePath()
|
||||
local _, sCurrProjectName = EgtSplitPath( sCurrProjectPath)
|
||||
local sResultFile = sCalcBaseDir .. '\\Results\\' .. sCurrProjectName .. '.csv'
|
||||
local bResultFile = EgtExistsFile( sResultFile)
|
||||
|
||||
-- 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
|
||||
|
||||
-- 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 nPartIndex = 1
|
||||
local nPartId = EgtGetFirstNameInGroup( GDB_ID.ROOT, PART .. nPartIndex)
|
||||
while nPartId do
|
||||
-- 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))
|
||||
-- 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 = EgtGetFirstGroupInGroup( nLayerId)
|
||||
while nCrvId do
|
||||
local nToolPathId = EgtGetFirstNameInGroup( nCrvId, TOOLPATH_GRP)
|
||||
EgtSetInfo( nToolPathId, KEY_FEED, dLayerFeed)
|
||||
EgtSetInfo( nToolPathId, KEY_SPEED, dSpeed)
|
||||
nCrvId = EgtGetNext( nCrvId)
|
||||
end
|
||||
-- riporto valori calcolati in tabella per csv
|
||||
local sStatus = ''
|
||||
if dEsteemedTime < dMinTime then
|
||||
sStatus = 'KO(-)'
|
||||
elseif dEsteemedTime > dMinTime and dEsteemedTime < dMaxTime then
|
||||
sStatus = 'OK'
|
||||
elseif dEsteemedTime > dMaxTime then
|
||||
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
|
||||
nPartIndex = nPartIndex + 1
|
||||
nPartId = EgtGetFirstNameInGroup( GDB_ID.ROOT, PART .. nPartIndex)
|
||||
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
|
||||
|
||||
------------------------- MAIN --------------------------------------
|
||||
-- Calcolo
|
||||
RMPC.Exec()
|
||||
|
||||
Reference in New Issue
Block a user