Files
DarioS 1bd70de55b Gunstock :
- modifiche Beretta per import Fagor
- correzione per variabili con nomi contenuti in nomi di altre (@A e @ANG).
2022-07-18 09:06:18 +02:00

1763 lines
66 KiB
Lua

-- Main.lua by Egaltech s.r.l. 2022/07/15
-- Main gestione lavorazioni Gunstock
-- Intestazioni
require( 'EgtBase')
_ENV = EgtProtectGlobal()
EgtEnableDebug( false)
local sBaseDir = EgtGetSourceDir()
EgtAddToPackagePath( sBaseDir .. 'LuaLibs\\?.lua')
EGB = require( 'EgtGunstockBase')
-----------------------------------------------------------------
-- *** Global Variables ***
-----------------------------------------------------------------
_G.GGD = {}
-----------------------------------------------------------------
-- *** Local Variables ***
-----------------------------------------------------------------
local m_sModName
local m_sMachName
local m_sAttr
local m_sSboName
local m_vParams = {} -- array di record : .sName, .dMin, .dMax, .dDef, .sVar
local m_vVals = {} -- array di valori dei parametri da file PEZ
local m_vVars = {}
local m_vRaw = {}
local m_vRawRef = {}
local m_vGunRef = {}
local m_vMachs = {} -- array di record : .sInfo, .sName, .nLay, .Ang, .PrepRot, [1]...[N] Tras o Rotaz
local m_dCoeffAlt = 1 -- coefficiente altezza per posizionamento due pezzi uno sopra l'altro
local m_vSboMove = {} -- parametri di movimento sbozzato : X, Y, R
-----------------------------------------------------------------
-- *** Local Constants ***
-----------------------------------------------------------------
local LEN_MAX_ASTA = 400
local LEN_MIN_RIFLE = 650
-----------------------------------------------------------------
-- *** MOD file parsing ***
-----------------------------------------------------------------
local function GetHeader()
local sLine = EGB.GetLine()
if not sLine then return false end
if not sLine:find( '#NOME', 1, true) then return false end
m_sModName = EgtTrim( sLine:gsub( '#NOME', ''))
sLine = EGB.GetLine()
if not sLine then return false end
if not sLine:find( '#MACH', 1, true) then return false end
m_sMachName = EgtTrim( sLine:gsub( '#MACH', ''))
sLine = EGB.GetLine()
if not sLine then return false end
if not sLine:find( '#ATTR', 1, true) then
EGB.UngetLine( sLine)
m_sAttr = ''
else
m_sAttr = EgtTrim( sLine:gsub( '#ATTR', ''))
end
return true
end
-----------------------------------------------------------------
local function GetParams()
m_vParams = {}
local sLine = EGB.GetLine()
if not sLine then return false end
-- facoltativo
if not sLine:find( '#PARAM', 1, true) then
EGB.UngetLine( sLine)
return true
end
while not sLine:find( '#END_PAR', 1, true) do
if not sLine:find( '#PARAM', 1, true) then return false end
local sParam = EgtTrim( sLine:gsub( '#PARAM', ''))
local vsTok = EgtSplitString( sParam, ' ')
local Param = {}
Param.sName = vsTok[1]
Param.dMin = tonumber( vsTok[2])
Param.dMax = tonumber( vsTok[3])
Param.dDef = tonumber( vsTok[4])
Param.sVar = vsTok[5]
table.insert( m_vParams, Param)
sLine = EGB.GetLine()
if not sLine then return false end
end
return true
end
-----------------------------------------------------------------
local function GetVars()
local sLine = EGB.GetLine()
if not sLine then return false end
while not sLine:find( '#END_VAR', 1, true) do
if not sLine:find( '#VAR', 1, true) then return false end
local sVar = EgtTrim( sLine:gsub( '#VAR', ''))
local vsTok = EgtSplitString( sVar, ' ')
local Var = {}
Var.sName = vsTok[1]
Var.sExpr = vsTok[2]
Var.dVal = nil
table.insert( m_vVars, Var)
sLine = EGB.GetLine()
if not sLine then return false end
end
return true
end
-----------------------------------------------------------------
local function GetRawDim()
local sLine = EGB.GetLine()
if not sLine then return false end
if not sLine:find( '#LUNG_GREZZO', 1, true) then return false end
m_vRaw.sLenExpr = EgtTrim( sLine:gsub( '#LUNG_GREZZO', ''))
m_vRaw.dLen = 0
sLine = EGB.GetLine()
if not sLine then return false end
if not sLine:find( '#LARG_GREZZO', 1, true) then return false end
m_vRaw.sLarExpr = EgtTrim( sLine:gsub( '#LARG_GREZZO', ''))
m_vRaw.dLar = 0
sLine = EGB.GetLine()
if not sLine then return false end
if not sLine:find( '#ALT_GREZZO', 1, true) then return false end
m_vRaw.sAltExpr = EgtTrim( sLine:gsub( '#ALT_GREZZO', ''))
m_vRaw.dAlt = 0
sLine = EGB.GetLine()
if not sLine then return false end
if not sLine:find( '#DOPPIO', 1, true) then
m_dCoeffAlt = 1
else
m_dCoeffAlt = EgtIf( EgtTrim( sLine:gsub( '#DOPPIO', '')) ~= '0', 2, 1)
sLine = EGB.GetLine()
if not sLine then return false end
end
if not sLine:find( '#SBO', 1, true) then
m_sSboName = nil
else
m_sSboName = EgtTrim( sLine:gsub( '#SBO', ''))
sLine = EGB.GetLine()
if not sLine then return false end
end
if not sLine:find( '#MUOVI_SBO', 1, true) then
m_vSboMove = nil
else
sLine = sLine:gsub( '#MUOVI_SBO', '')
local vsTok = EgtSplitStringPlus( sLine, 'XYR')
m_vSboMove.sX = '0' ; m_vSboMove.dX = 0
m_vSboMove.sY = '0' ; m_vSboMove.dY = 0
m_vSboMove.sR = '0' ; m_vSboMove.dR = 0
for i = 1, #vsTok do
local sId = string.sub( vsTok[i], 1, 1)
if sId == 'X' then
m_vSboMove.sX = EgtTrim( string.sub( vsTok[i], 2))
elseif sId == 'Y' then
m_vSboMove.sY = EgtTrim( string.sub( vsTok[i], 2))
elseif sId == 'R' then
m_vSboMove.sR = EgtTrim( string.sub( vsTok[i], 2))
end
end
sLine = EGB.GetLine()
if not sLine then return false end
end
return sLine:find( '#END_DIM_GREZZO', 1, true)
end
-----------------------------------------------------------------
local function GetStartStdMachining()
local sLine = EGB.GetLine()
if not sLine then return false end
return sLine:find( '#LAV_PIA_', 1, true)
end
-----------------------------------------------------------------
local function GetEndStdMachining()
local sLine = EGB.GetLine()
if not sLine then return true end
if sLine:find( '#END_PIA_', 1, true) then
return true
else
EGB.UngetLine( sLine)
return false
end
end
-----------------------------------------------------------------
local function ParseTras( sParam)
local Tras = {}
Tras.Type = 1
sParam = sParam:gsub( 'X', '')
sParam = sParam:gsub( 'Y', ',')
sParam = sParam:gsub( 'Z', ',')
local vsTok = EgtSplitString( sParam, ',')
if #vsTok < 3 then return nil end
Tras.sXExpr = vsTok[1]
Tras.sYExpr = vsTok[2]
Tras.sZExpr = vsTok[3]
Tras.dX = 0
Tras.dY = 0
Tras.dZ = 0
return Tras
end
-----------------------------------------------------------------
local function ParseRotaz( sParam)
local Rotaz = {}
Rotaz.Type = 2
local vsTok = EgtSplitString( sParam, ' ')
if #vsTok < 3 then return nil end
Rotaz.sAx = vsTok[1]
Rotaz.sMode = vsTok[2]
Rotaz.sAngExpr = vsTok[3]
Rotaz.dAng = 0
return Rotaz
end
-----------------------------------------------------------------
local function GetRawRef()
local sLine = EGB.GetLine()
if not sLine then return false end
if not sLine:find( '#RIF_GRE', 1, true) then return false end
sLine = EGB.GetLine()
if not sLine then return false end
while not sLine:find( '#END_RIF', 1, true) do
if sLine:find( '#TRAS', 1, true) then
local sParam = EgtTrim( sLine:gsub( '#TRAS', ''))
local Tras = ParseTras( sParam)
if not Tras then return false end
table.insert( m_vRawRef, Tras)
elseif sLine:find( '#ROTAZ', 1, true) then
local sParam = EgtTrim( sLine:gsub( '#ROTAZ', ''))
local Rotaz = ParseRotaz( sParam)
if not Rotaz then return false end
table.insert( m_vRawRef, Rotaz)
else
return false
end
sLine = EGB.GetLine()
if not sLine then return false end
end
return true
end
-----------------------------------------------------------------
local function GetGunRef()
local sLine = EGB.GetLine()
if not sLine then return false end
if not sLine:find( '#RIF_FUCILE', 1, true) then return false end
sLine = EGB.GetLine()
if not sLine then return false end
while not sLine:find( '#END_RIF', 1, true) do
if sLine:find( '#TRAS', 1, true) then
local sParam = EgtTrim( sLine:gsub( '#TRAS', ''))
local Tras = ParseTras( sParam)
if not Tras then return false end
table.insert( m_vGunRef, Tras)
elseif sLine:find( '#ROTAZ', 1, true) then
local sParam = EgtTrim( sLine:gsub( '#ROTAZ', ''))
local Rotaz = ParseRotaz( sParam)
if not Rotaz then return false end
table.insert( m_vGunRef, Rotaz)
else
return false
end
sLine = EGB.GetLine()
if not sLine then return false end
end
return true
end
-----------------------------------------------------------------
local function GetMachining( bBeretta)
-- inizio lavorazione
local sLine = EGB.GetLine()
if not sLine then return false end
if not sLine:find( '#LAV', 1, true) then return false end
local vMach = {}
vMach.sInfo = EGB.GetLastRem()
vMach.sName = EgtTrim( sLine:gsub( '#LAV', ''))
sLine = EGB.GetLine()
if not sLine then return false end
while not sLine:find( '#END_SING_LAV', 1, true) do
if sLine:find( '#TRAS', 1, true) then
local sParam = EgtTrim( sLine:gsub( '#TRAS', ''))
local Tras = ParseTras( sParam)
if not Tras then return false end
table.insert( vMach, Tras)
elseif sLine:find( '#ROTAZ', 1, true) then
local sParam = EgtTrim( sLine:gsub( '#ROTAZ', ''))
local Rotaz = ParseRotaz( sParam)
if not Rotaz then return false end
table.insert( vMach, Rotaz)
elseif sLine:find( '#ANG', 1, true) then
local sParam = EgtTrim( sLine:gsub( '#ANG', ''))
local vsTok = EgtSplitString( sParam, ' ')
if #vsTok < 2 then return false end
local Ang = {}
Ang.sR1Expr = vsTok[1]
Ang.dR1 = 0
Ang.sR2Expr = vsTok[2]
Ang.dR2 = 0
vMach.Ang = Ang
elseif sLine:find( '#TESTA_USCITA', 1, true) then
--
elseif sLine:find( '#PREP_ROT', 1, true) then
if not bBeretta then
local sParam = EgtTrim( sLine:gsub( '#PREP_ROT', ''))
local vsTok = EgtSplitString( sParam, ' ')
if #vsTok < 2 then return false end
local PrepRot = {}
PrepRot.sR1Expr = vsTok[1]
PrepRot.dR1 = 0
PrepRot.sR2Expr = vsTok[2]
PrepRot.dR2 = 0
PrepRot.sFeedExpr = vsTok[3]
PrepRot.dFeed = 0
vMach.PrepRot = PrepRot
end
else
return false
end
sLine = EGB.GetLine()
if not sLine then return false end
end
table.insert( m_vMachs, vMach)
return true
end
-----------------------------------------------------------------
-- *** Evaluate MOD expression ***
-----------------------------------------------------------------
local function AdjustFunction( sTmp, sOri, sNewS, sNewE)
local nEnd = sTmp:find( sOri, 1, true)
while nEnd do
-- ricerca corrispondente parentesi aperta
local nSta = nEnd - 1
local nCount = 1
while sTmp:sub(nSta,nSta) ~= '(' or nCount > 1 do
if sTmp:sub(nSta,nSta) == ')' then
nCount = nCount + 1
elseif sTmp:sub(nSta,nSta) == '(' then
nCount = nCount - 1
end
nSta = nSta - 1
if nSta == 0 then
return nil
end
end
-- sostituzioni
sTmp = sTmp:sub( 1, nEnd - 1) .. sNewE .. sTmp:sub( nEnd + sOri:len())
sTmp = sTmp:sub( 1, nSta - 1) .. sNewS .. sTmp:sub( nSta + 1)
-- nuova ricerca
nEnd = sTmp:find( sOri, 1, true)
end
return sTmp
end
-----------------------------------------------------------------
local function EvaluateExpr( sExpr)
local sTmp = sExpr or ''
-- sostituzione valori dei parametri
for i = 1, #m_vParams do
local Param = m_vParams[i]
if Param.dVal >= 0 then
sTmp = sTmp:gsub( '@'..Param.sName, EgtNumToString( Param.dVal, 3))
else
sTmp = sTmp:gsub( '@'..Param.sName, '('..EgtNumToString( Param.dVal, 3)..')')
end
end
-- sostituzione valori delle variabili
for i = 1, #m_vVars do
local Var = m_vVars[i]
if Var.dVal then
if Var.dVal >= 0 then
sTmp = sTmp:gsub( '@'..Var.sName, EgtNumToString( Var.dVal, 3))
else
sTmp = sTmp:gsub( '@'..Var.sName, '('..EgtNumToString( Var.dVal, 3)..')')
end
end
end
-- sostituzione costanti
sTmp = sTmp:gsub( 'P', 'pi')
-- sistemazione funzioni
sTmp = AdjustFunction( sTmp, ')Q', 'pow(', ',2)')
sTmp = AdjustFunction( sTmp, ')R', 'sqrt(', ')')
sTmp = AdjustFunction( sTmp, ')S', 'sin(', ')')
sTmp = AdjustFunction( sTmp, 'S)', 'sin(', ')')
sTmp = AdjustFunction( sTmp, ')C', 'cos(', ')')
sTmp = AdjustFunction( sTmp, 'C)', 'cos(', ')')
sTmp = AdjustFunction( sTmp, ')T', 'tan(', ')')
sTmp = AdjustFunction( sTmp, 'T)', 'tan(', ')')
sTmp = AdjustFunction( sTmp, ')AS', 'asin(', ')')
sTmp = AdjustFunction( sTmp, ')AC', 'acos(', ')')
sTmp = AdjustFunction( sTmp, ')AT', 'atan(', ')')
-- valutazione espressione
return EgtEvalNumExpr( sTmp)
end
-----------------------------------------------------------------
local function EvaluateVars()
for i = 1, #m_vVars do
-- eseguo valutazione
local Var = m_vVars[i]
Var.dVal = EvaluateExpr( Var.sExpr)
if not Var.dVal then
EGB.WriteErrLine( 'ERR=106\nErrore nella valutazione della variabile '.. Var.sName)
GGD.ERR = 106
return
end
-- ordino le valutate in ordine decrescente di lunghezza del nome
for j = 1, i do
for k = j + 1, i do
local VarJ = m_vVars[j]
local VarK = m_vVars[k]
if #( VarK.sName) > #( VarJ.sName) then
m_vVars[j], m_vVars[k] = m_vVars[k], m_vVars[j]
end
end
end
end
for i = 1, #m_vVars do
local Var = m_vVars[i]
EgtOutLog( 'Var = ' .. Var.sName .. ' ' .. Var.sExpr .. ' -> ' .. EgtNumToString( Var.dVal, 3))
end
end
-----------------------------------------------------------------
local function EvaluateRawDim()
m_vRaw.dLen = EvaluateExpr( m_vRaw.sLenExpr)
m_vRaw.dLar = EvaluateExpr( m_vRaw.sLarExpr)
m_vRaw.dAlt = EvaluateExpr( m_vRaw.sAltExpr)
if not m_vRaw.dLen or not m_vRaw.dLar or not m_vRaw.dAlt then
EGB.WriteErrLine( 'ERR=108\nErrore nella valutazione delle dimensioni del grezzo')
GGD.ERR = 108
return
end
EgtOutLog( 'RawLen = ' .. m_vRaw.sLenExpr .. ' -> ' .. EgtNumToString( m_vRaw.dLen, 3))
EgtOutLog( 'RawLar = ' .. m_vRaw.sLarExpr .. ' -> ' .. EgtNumToString( m_vRaw.dLar, 3))
EgtOutLog( 'RawAlt = ' .. m_vRaw.sAltExpr .. ' -> ' .. EgtNumToString( m_vRaw.dAlt, 3))
if m_vSboMove then
m_vSboMove.dX = EvaluateExpr( m_vSboMove.sX)
m_vSboMove.dY = EvaluateExpr( m_vSboMove.sY)
m_vSboMove.dR = EvaluateExpr( m_vSboMove.sR)
EgtOutLog( 'MoveSbo X = ' .. m_vSboMove.sX .. ' -> ' .. EgtNumToString( m_vSboMove.dX, 3))
EgtOutLog( 'MoveSbo Y = ' .. m_vSboMove.sY .. ' -> ' .. EgtNumToString( m_vSboMove.dY, 3))
EgtOutLog( 'MoveSbo R = ' .. m_vSboMove.sR .. ' -> ' .. EgtNumToString( m_vSboMove.dR, 3))
end
end
-----------------------------------------------------------------
local function WriteOutLineFromIni( sSec, sKey, sDef, sIniFile)
local sLine = EgtGetStringFromIni( sSec, sKey, sDef, sIniFile)
if #sLine == 0 then return end
EGB.WriteOutLine( sLine:gsub( '<br/>', '\n'))
end
-----------------------------------------------------------------
local function CncSplit( sCncFile, sSubDir)
local CncFh = io.open( sCncFile, 'r')
if not CncFh then
EgtOutLog( 'Errore nell\'apertura del file di input ' .. sCncFile)
return false
end
local SubFh
local sLine = CncFh:read( '*l')
while sLine do
if not string.find( sLine, '%', 1, true) then
if string.find( sLine, '(DIS,"CODICE=SUB', 1, true) then
if SubFh then
SubFh:close()
SubFh = nil
end
local sSubName = string.sub( sLine, 14, -3)
local sSubFile = sSubDir..sSubName
SubFh = io.open( sSubFile, 'w')
if not SubFh then
EgtOutLog( 'Errore nell\'apertura del file di output ' .. sSubFile)
CncFh:close()
return false
end
end
if SubFh then
-- se chiamata di testa
if string.find( sLine, 'T', 1, true) and string.find( sLine, 'M06', 1, true) then
-- leggo numero di testa
local vTok = EgtSplitStringPlus( sLine, 'TMD.')
local nT = 0
for i = 1, #vTok do
if vTok[i]:sub( 1, 1) == 'T' then
nT = tonumber( vTok[i]:sub( 2))
break
end
end
if nT == 0 then
EgtOutLog( 'Errore lettura richiamo testa nel file ' .. sCncFile..' alla linea '..sLine)
CncFh:close()
SubFh:close()
return false
end
-- verifico presenza richiamo correttore
local bCorr = false
for i = 1, #vTok do
if vTok[i]:sub( 1, 1) == '.' then
bCorr = true
break
end
end
-- conversione numero di testa
local vConv = { [31] = 11, [32] = 18, [33] = 17}
if vConv[nT] then nT = vConv[nT] end
-- scrivo nuove linee
local sT = EgtNumToString( nT)
if #sT == 1 then sT = '0'..sT end
SubFh:write( 'T'..sT..' M06\n')
if bCorr then
SubFh:write( 'h'..EgtNumToString( nT)..'\n')
end
-- altrimenti conversioni
else
sLine = sLine:gsub( 'T21', '')
sLine = sLine:gsub( 'T41', '')
sLine = sLine:gsub( 'T42', '')
sLine = sLine:gsub( 'T43', '')
sLine = sLine:gsub( 'M60', '')
sLine = sLine:gsub( 'U0', 'C0')
-- se non vuota, scrittura linea
if #sLine > 0 then
SubFh:write( sLine .. '\n')
end
end
end
end
sLine = CncFh:read( '*l')
end
if SubFh then SubFh:close() end
CncFh:close()
return true
end
-----------------------------------------------------------------
-- *** Read MOD params ***
-----------------------------------------------------------------
function GGD.ReadModParams()
-- Path completa file MOD
local sModFile = GGD.MODFILE
-- Apertura file MOD
if not EGB.OpenFile( sModFile) then
EgtOutLog( 'ERR=102\nErrore nell\'apertura del file ' .. sModFile)
GGD.ERR = 102
return
end
-- Recupero header modello
if not GetHeader() then
EgtOutLog( 'ERR=103\nErrore in lettura NOME o MACH')
GGD.ERR = 103
return
end
GGD.MODNAME = m_sModName
EgtOutLog( 'Name = ' .. m_sModName .. ' Mach = ' .. m_sMachName .. ' Attr = ' .. m_sAttr)
-- Recupero parametri (opzionali)
if not GetParams() then
EgtOutLog( 'ERR=104\nErrore in lettura PARAM')
GGD.ERR = 104
return
end
GGD.PARTOT = #m_vParams
for i = 1, #m_vParams do
local Param = m_vParams[i]
EgtOutLog( 'Param = '..Param.sName..' '..EgtNumToString( Param.dMin, 1)..' '..EgtNumToString( Param.dMax, 1)..
' '..EgtNumToString( Param.dDef, 1) .. ' ' .. Param.sVar)
local sParNameI = 'PARNAME' .. tostring(i)
GGD[sParNameI] = Param.sName
local sParMinI = 'PARMIN' .. tostring(i)
GGD[sParMinI] = Param.dMin
local sParMaxI = 'PARMAX' .. tostring(i)
GGD[sParMaxI] = Param.dMax
local sParDefI = 'PARDEF' .. tostring(i)
GGD[sParDefI] = Param.dDef
local sParVarI = 'PARVAR' .. tostring(i)
GGD[sParVarI] = Param.sVar
end
for i = 1, #m_vParams do
local Param = m_vParams[i]
Param.dVal = Param.dDef
end
-- Recupero variabili (come espressioni)
if not GetVars() then
EGB.WriteErrLine( 'ERR=105\nErrore in lettura VAR')
GGD.ERR = 105
return
end
-- Recupero dimensioni grezzo (come espressioni)
if not GetRawDim() then
EGB.WriteErrLine( 'ERR=107\nErrore in lettura DIM_GREZZO')
GGD.ERR = 107
return
end
-- Chiusura file MOD
EGB.CloseFile()
GGD.ERR = 0
end
-----------------------------------------------------------------
-- *** Read PEZ params ***
-----------------------------------------------------------------
function GGD.ReadPezParams()
-- Path completa file PEZ
local sPezFile = GGD.PEZFILE
-- Direttorio del modello
local sPezDir = EgtSplitPath( sPezFile)
local sModDir = sPezDir:sub( 1, -5) .. 'MOD\\'
--EgtOutLog( 'ModDir='..sModDir)
-- Apertura file PEZ
local PezFh = io.open( sPezFile, 'r')
if not PezFh then
EgtOutLog( 'ERR=117\nErrore nell\'apertura del file ' .. sPezFile)
GGD.ERR = 117
return
end
-- Lettura parametri generali
local sLine = PezFh:read( '*l')
-- identificativo, non interessa
sLine = PezFh:read( '*l')
if sLine then
GGD.DESCR = EgtTrim( sLine:gsub( 'Descrizione :', '') or '')
end
sLine = PezFh:read( '*l')
if sLine then
local sModFile = EgtTrim( sLine:gsub( 'Modello :', '' ) or '')
local _, sModName, sModExt = EgtSplitPath( sModFile)
GGD.MODFILE = sModDir .. sModName .. sModExt
else
EgtOutLog( 'ERR=118\nErrore nella lettura del nome del modello da ' .. sPezFile)
GGD.ERR = 118
return
end
sLine = PezFh:read( '*l')
if sLine then
GGD.DIMGREZ = EgtTrim( sLine:gsub( 'Dim. Grezzo :', '' ) or '')
end
-- Lettura parametri modello
GGD.ReadModParams()
if GGD.ERR ~= 0 then
return
end
-- Continuo lettura parametri generici pezzo
for i = 1, #m_vParams do
sLine = PezFh:read( '*l')
if sLine then
local sVal = EgtTrim( sLine:gsub( m_vParams[i].sName .. ' :', '' ) or '')
m_vParams[i].dVal = tonumber( sVal)
end
end
-- Chiusura file PEZ
PezFh:close()
-- Assegno valori letti
for i = 1, #m_vParams do
local sParValI = 'PARVAL' .. tostring(i)
GGD[sParValI] = m_vParams[i].dVal
end
GGD.ERR = 0
end
-----------------------------------------------------------------
-- *** Write PEZ params ***
-----------------------------------------------------------------
function GGD.WritePezParams()
-- Assegnazione parametri
for i = 1, #m_vParams do
local sParValI = 'PARVAL' .. tostring(i)
m_vParams[i].dVal = GGD[sParValI]
m_vVals[i] = m_vParams[i].dVal
end
-- Valutazione variabili
EvaluateVars()
if GGD.ERR ~= 0 then
return
end
-- Valutazione dimensioni grezzo
EvaluateRawDim()
if GGD.ERR ~= 0 then
return
end
GGD.DIMGREZ = EgtNumToString( m_vRaw.dLen, 3) .. ' x ' ..
EgtNumToString( m_vRaw.dLar, 3) .. ' x ' ..
EgtNumToString( m_vRaw.dAlt, 3)
-- Path completa file PEZ
local sPezFile = GGD.PEZFILE
local sPezDir, sPezName, sPezExt = EgtSplitPath( sPezFile)
-- Apertura file PEZ
local PezFh = io.open( sPezFile, 'w')
if not PezFh then
EgtOutLog( 'ERR=116\nErrore nell\'apertura del file ' .. sPezFile)
GGD.ERR = 116
return
end
-- Scrittura parametri
PezFh:write( 'Identificativo : ' .. sPezName .. '\n')
PezFh:write( 'Descrizione : ' .. GGD.DESCR .. '\n')
PezFh:write( 'Modello : ' .. GGD.MODFILE .. '\n')
PezFh:write( 'Dim. Grezzo : ' .. GGD.DIMGREZ .. '\n')
for i = 1, #m_vParams do
PezFh:write( m_vParams[i].sName .. ' : ' .. EgtNumToString( m_vParams[i].dVal, 3) .. '\n')
end
-- Chiusura file PEZ
PezFh:close()
GGD.ERR = 0
end
-----------------------------------------------------------------
-- *** GUNSTOCK creation with MOD parse ***
-----------------------------------------------------------------
function GGD.CreateGunstock()
local bOk = true
local sModFile = GGD.MODFILE
local sPezFile = GGD.PEZFILE
local sModDir, sModName, sModExt = EgtSplitPath( sModFile)
local sPezDir, sPezName, sPezExt = EgtSplitPath( sPezFile)
local sBaseDir = sPezDir:sub( 1, -5)
local sSboDir = sBaseDir .. 'SBO\\'
local sSubDir = sBaseDir .. 'SUB\\'
local sTmpDir = sBaseDir .. 'TMP\\'
local sErrFile = sPezDir .. sPezName .. '.txt'
local sCncFile = sBaseDir .. 'CNC\\' .. sPezName
local sCncMazFile = sCncFile..'.EIA'
local sNgeFile = sPezDir .. sPezName .. '.nge'
-- Messaggi di inizio
EgtOutLog( 'Pez = ' .. sPezFile .. ' Model = ' .. sModFile)
-- Cancello tutti i file di output
EgtEraseFile( sErrFile)
EgtEraseFile( sCncFile)
EgtEraseFile( sCncMazFile)
EgtEraseFile( sNgeFile)
-- Pulisco il direttorio temporaneo
EgtEmptyDirectory( sTmpDir)
-- Apertura file errori
if not EGB.OpenErrFile( sErrFile) then
EgtOutLog( '(ERR=101) Errore nell\'apertura del file degli errori' .. sErrFile)
GGD.ERR = 101
return
end
-- Apertura file MOD
if not EGB.OpenFile( sModFile) then
EGB.WriteErrLine( 'ERR=102\nErrore nell\'apertura del file ' .. sModFile)
GGD.ERR = 102
return
end
-- Recupero header modello
if not GetHeader() then
EGB.WriteErrLine( 'ERR=103\nErrore in lettura NOME o MACH')
GGD.ERR = 103
return
end
EgtOutLog( 'Name = ' .. m_sModName .. ' Mach = ' .. m_sMachName .. ' Attr = ' .. m_sAttr)
if not EgtSetCurrMachine( m_sMachName) then
EGB.WriteErrLine( 'ERR=119\nErrore impostando la macchina corrente ' .. m_sMachName)
GGD.ERR = 119
return
end
local sMachIni = EgtGetCurrMachineDir() .. '\\' .. m_sMachName .. '.ini'
local bTwoHeads = ( EgtGetStringFromIni( 'Gunstock', 'TwoHeads', '0', sMachIni) == '1')
local bAddM6ToT3x = ( EgtGetStringFromIni( 'Gunstock', 'AddM6ToT3x', '1', sMachIni) == '1')
local sType = EgtGetStringFromIni( 'Gunstock', 'Type', 'Cms', sMachIni)
local bBeretta = false
local bMazak = false
if sType == 'Beretta' then
bBeretta = true
elseif sType == 'Mazak' then
bMazak = true
end
-- In modalità Beretta recupero SUB dal file CNC omonimo di MOD
if bBeretta then
EgtEmptyDirectory( sSubDir)
local sCncFile = EgtChangePathExtension( sModFile, 'CNC')
if not CncSplit( sCncFile, sSubDir) then
EGB.WriteErrLine( 'ERR=120\nErrore in CNC file split')
GGD.ERR = 120
return
end
end
-- Recupero parametri (opzionali)
if not GetParams() then
EGB.WriteErrLine( 'ERR=104\nErrore in lettura PARAM')
GGD.ERR = 104
return
end
-- assegno i valori dal pezzo
for i = 1, #m_vParams do
local Param = m_vParams[i]
Param.dVal = m_vVals[i]
end
for i = 1, #m_vParams do
local Param = m_vParams[i]
EgtOutLog( 'Param = ' .. Param.sName ..
' ' .. EgtNumToString( Param.dMin, 1) .. ' ' .. EgtNumToString( Param.dMax, 1) ..
' ' .. EgtNumToString( Param.dDef, 1) .. ' ' .. Param.sVar ..
' -> ' .. EgtNumToString( Param.dVal, 1))
end
-- Recupero variabili e ne valuto le espressioni
if not GetVars() then
EGB.WriteErrLine( 'ERR=105\nErrore in lettura VAR')
GGD.ERR = 105
return
end
EvaluateVars()
if GGD.ERR ~= 0 then
return
end
-- Recupero dimensioni grezzo e ne valuto le espressioni
if not GetRawDim() then
EGB.WriteErrLine( 'ERR=107\nErrore in lettura DIM_GREZZO')
GGD.ERR = 107
return
end
EvaluateRawDim()
if GGD.ERR ~= 0 then
return
end
-- Inizio lavorazioni piane
if not GetStartStdMachining() then
EGB.WriteErrLine( 'ERR=109\nErrore in lettura LAV_PIA_1')
GGD.ERR = 109
return
end
-- Recupero posizione grezzo e ne valuto le espressioni
if not GetRawRef() then
EGB.WriteErrLine( 'ERR=110\nErrore in lettura RIF_GRE')
GGD.ERR = 110
return
end
local bRawRefEval = true
for i = 1, #m_vRawRef do
local RawRef = m_vRawRef[i]
if RawRef.Type == 1 then
RawRef.dX = EvaluateExpr( RawRef.sXExpr)
RawRef.dY = EvaluateExpr( RawRef.sYExpr)
RawRef.dZ = EvaluateExpr( RawRef.sZExpr)
if not RawRef.dX or not RawRef.dY or not RawRef.dZ then bRawRefEval = false end
elseif RawRef.Type == 2 then
RawRef.dAng = EvaluateExpr( RawRef.sAngExpr)
if ( not RawRef.dAng or
( RawRef.sAx ~= 'X' and RawRef.sAx ~= 'Y' and RawRef.sAx ~= 'Z') or
( RawRef.sMode ~= 'F' and RawRef.sMode ~= 'M')) then bRawRefEval = false end
end
end
if not bRawRefEval then
EGB.WriteErrLine( 'ERR=111\nErrore nella valutazione del riferimento del grezzo')
GGD.ERR = 111
return
end
EgtOutLog( 'RawRef')
for i = 1, #m_vRawRef do
local RawRef = m_vRawRef[i]
if RawRef.Type == 1 then
EgtOutLog( 'Tras = X'..EgtNumToString( RawRef.dX, 3)..' Y'..EgtNumToString( RawRef.dY, 3)..
' Z'..EgtNumToString( RawRef.dZ, 3))
elseif RawRef.Type == 2 then
EgtOutLog( 'Rotaz = '..RawRef.sAx..' '..RawRef.sMode..' '..EgtNumToString( RawRef.dAng, 3))
end
end
-- Recupero posizione finito e ne valuto le espressioni
if not GetGunRef() then
EGB.WriteErrLine( 'ERR=112\nErrore in lettura RIF_FUCILE')
GGD.ERR = 112
return
end
local bGunRefEval = true
for i = 1, #m_vGunRef do
local GunRef = m_vGunRef[i]
if GunRef.Type == 1 then
GunRef.dX = EvaluateExpr( GunRef.sXExpr)
GunRef.dY = EvaluateExpr( GunRef.sYExpr)
GunRef.dZ = EvaluateExpr( GunRef.sZExpr)
if not GunRef.dX or not GunRef.dY or not GunRef.dZ then bGunRefEval = false end
elseif GunRef.Type == 2 then
GunRef.dAng = EvaluateExpr( GunRef.sAngExpr)
if ( not GunRef.dAng or
( GunRef.sAx ~= 'X' and GunRef.sAx ~= 'Y' and GunRef.sAx ~= 'Z') or
( GunRef.sMode ~= 'F' and GunRef.sMode ~= 'M')) then bGunRefEval = false end
end
end
if not bGunRefEval then
EGB.WriteErrLine( 'ERR=113\nErrore nella valutazione del riferimento del pezzo')
GGD.ERR = 113
return
end
EgtOutLog( 'GunRef')
for i = 1, #m_vGunRef do
local GunRef = m_vGunRef[i]
if GunRef.Type == 1 then
EgtOutLog( 'Tras = X'..EgtNumToString( GunRef.dX, 3)..' Y'..EgtNumToString( GunRef.dY, 3)..
' Z'..EgtNumToString( GunRef.dZ, 3))
elseif GunRef.Type == 2 then
EgtOutLog( 'Rotaz = '..GunRef.sAx..' '..GunRef.sMode..' '..EgtNumToString( GunRef.dAng, 3))
end
end
-- Recupero dati di lavorazione
while not GetEndStdMachining() do
if not GetMachining( bBeretta) then
EGB.WriteErrLine( 'ERR=114\nErrore in lettura Lavorazione (linea ' .. tostring( EGB.GetLineNumber()) ..')')
GGD.ERR = 114
return
end
local bStdMachEval = true
local vMach = m_vMachs[#m_vMachs]
if vMach.Ang then
vMach.Ang.dR1 = EvaluateExpr( vMach.Ang.sR1Expr)
vMach.Ang.dR2 = EvaluateExpr( vMach.Ang.sR2Expr)
if not vMach.Ang.dR1 or not vMach.Ang.dR2 then bStdMachEval = false end
end
if vMach.PrepRot then
vMach.PrepRot.dR1 = EvaluateExpr( vMach.PrepRot.sR1Expr)
vMach.PrepRot.dR2 = EvaluateExpr( vMach.PrepRot.sR2Expr)
vMach.PrepRot.dFeed = EvaluateExpr( vMach.PrepRot.sFeedExpr)
if not vMach.PrepRot.dR1 or not vMach.PrepRot.dR2 or not vMach.PrepRot.dFeed then bStdMachEval = false end
end
for i = 1, #vMach do
local Data = vMach[i]
if Data.Type == 1 then
Data.dX = EvaluateExpr( Data.sXExpr)
Data.dY = EvaluateExpr( Data.sYExpr)
Data.dZ = EvaluateExpr( Data.sZExpr)
if not Data.dX or not Data.dY or not Data.dZ then bStdMachEval = false end
elseif Data.Type == 2 then
Data.dAng = EvaluateExpr( Data.sAngExpr)
if ( not Data.dAng or
( Data.sAx ~= 'X' and Data.sAx ~= 'Y' and Data.sAx ~= 'Z') or
( Data.sMode ~= 'F' and Data.sMode ~= 'M')) then bStdMachEval = false end
end
end
if not bStdMachEval then
EGB.WriteErrLine( 'ERR=115\nErrore nella valutazione della lavorazione '.. vMach.sName)
GGD.ERR = 115
return
end
EgtOutLog( 'Mach ' .. vMach.sName)
EgtOutLog( 'Info = ' .. vMach.sInfo)
if vMach.Ang then
EgtOutLog( 'Ang = '..EgtNumToString( vMach.Ang.dR1, 3)..' '..EgtNumToString( vMach.Ang.dR2, 3))
end
if vMach.PrepRot then
EgtOutLog( 'PrepRot = '..EgtNumToString( vMach.PrepRot.dR1, 3)..' '..EgtNumToString( vMach.PrepRot.dR2, 3)..
' '..EgtNumToString( vMach.PrepRot.dFeed, 3))
end
for i = 1, #vMach do
local Data = vMach[i]
if Data.Type == 1 then
EgtOutLog( 'Tras = X'..EgtNumToString( Data.dX, 3)..' Y'..EgtNumToString( Data.dY, 3)..
' Z'..EgtNumToString( Data.dZ, 3))
elseif Data.Type == 2 then
EgtOutLog( 'Rotaz = '..Data.sAx..' '..Data.sMode..' '..EgtNumToString( Data.dAng, 3))
end
end
end
-- Chiusura file MOD
EGB.CloseFile()
-- Creazione grezzo
EgtNewFile()
local Pz = EgtGroup( GDB_ID.ROOT)
EgtSetName( Pz, 'GUNSTOCK')
local Ly = EgtGroup( Pz)
EgtSetName( Ly, 'SOLID')
local Sol
-- se definito sbozzato
if m_sSboName then
-- Inserimento file
local sSboFile = sSboDir .. m_sSboName
if EgtInsertFile( sSboFile) then
-- Spostamento contorno nel layer del solido
local nPz = EgtGetLastPart()
local nLay = EgtGetFirstLayer( nPz)
local nId = EgtGetFirstInGroup( nLay or GDB_ID.NULL)
EgtRelocate( nId, Ly)
EgtErase( nPz)
-- Lo spiano a Z=0
EgtScale( nId, GLOB_FRM(), 1, 1, 0, GDB_RT.GLOB)
-- Eventuale rototraslazione
if m_vSboMove then
EgtRotate( nId, ORIG(), Z_AX(), m_vSboMove.dR, GDB_RT.GLOB)
EgtMove( nId, Vector3d( m_vSboMove.dX, m_vSboMove.dY, 0))
end
-- Creazione del solido
Sol = EgtSurfTmByRegionExtrusion( Ly, nId, Z_AX() * m_vRaw.dAlt * m_dCoeffAlt)
else
EgtOutLog( 'Error in InsertFile ' .. sSboFile)
end
end
-- creo parallelepipedo
if not Sol then
Sol = EgtSurfTmBox( Ly, ORIG(), Point3d( m_vRaw.dLen, -m_vRaw.dLar, 0), Point3d(10,0,0), m_vRaw.dAlt * m_dCoeffAlt, GDB_RT.GLOB)
end
EgtSetName( Sol, 'SOLID')
EgtSetColor( Sol, ORANGE())
EgtSetAlpha( Sol, 30)
-- calcolo delta tra Zero solido (sbozzato) e Zero teorico del grezzo
local b3Sol = EgtGetBBoxGlob( Sol, GDB_BB.EXACT)
local vtSolDelta = Vector3d( b3Sol:getMin():getX(), b3Sol:getMax():getY(), 0)
-- Calcolo riferimento del fucile
local frGun = Frame3d( GLOB_FRM())
for i = 1, #m_vGunRef do
local GunRef = m_vGunRef[i]
if GunRef.Type == 1 then
local vtMove = GunRef.dX * frGun:getVersX() + GunRef.dY * frGun:getVersY() + GunRef.dZ * frGun:getVersZ()
frGun:move( vtMove)
elseif GunRef.Type == 2 then
local vtAx
if GunRef.sAx == 'X' then
if GunRef.sMode == 'F' then vtAx = X_AX() else vtAx = frGun:getVersX() end
elseif GunRef.sAx == 'Y' then
if GunRef.sMode == 'F' then vtAx = Y_AX() else vtAx = frGun:getVersY() end
else -- 'Z'
if GunRef.sMode == 'F' then vtAx = Z_AX() else vtAx = frGun:getVersZ() end
end
frGun:rotate( frGun:getOrigin(), vtAx, GunRef.dAng)
end
end
-- Elaborazione delle lavorazioni
for i = 1, #m_vMachs do
-- lavorazione i-esima
local vMach = m_vMachs[i]
-- riferimento della lavorazione
local frMach = Frame3d( frGun)
for i = 1, #vMach do
local Data = vMach[i]
if Data.Type == 1 then
local vtMove = Data.dX * frMach:getVersX() + Data.dY * frMach:getVersY() + Data.dZ * frMach:getVersZ()
frMach:move( vtMove)
elseif Data.Type == 2 then
local vtAx
if Data.sAx == 'X' then
if Data.sMode == 'F' then vtAx = frGun:getVersX() else vtAx = frMach:getVersX() end
elseif Data.sAx == 'Y' then
if Data.sMode == 'F' then vtAx = frGun:getVersY() else vtAx = frMach:getVersY() end
else -- 'Z'
if Data.sMode == 'F' then vtAx = frGun:getVersZ() else vtAx = frMach:getVersZ() end
end
frMach:rotate( frMach:getOrigin(), vtAx, Data.dAng)
end
end
-- creo il layer
local Lm = EgtGroup( Pz, frMach)
EgtSetName( Lm, vMach.sName)
vMach.nLay = Lm
-- inserisco riferimento
local l = EgtFrame( Lm, Frame3d( ORIG()))
EgtSetName( l, 'Ref')
-- inserimento lavorazione (in ordine crecente di E)
local vSubst
local sSubName
local sSubExt
if bMazak then
sSubName = vMach.sName
sSubExt = '.EIA'
else
vSubst = { {'E1', '25.5'}, {'E2', '25.5'}, {'E101', '25.5'}, {'E102', '25.5'}}
sSubName = 'Sub'..vMach.sName
end
if not EGB.ImportCnc( sSubDir, sTmpDir, sSubName, sSubExt, vSubst, bAddM6ToT3x, vMach.nLay) then
EgtOutLog( 'Errore inserimento percorso di lavorazione ' .. vMach.sName)
end
end
EgtSetGridFrame()
-- Gestione macchina
local sMachineName = EgtGetCurrMachineName()
if not sMachineName then
EGB.WriteErrLine( 'ERR=201\nErrore : non esiste una macchina corrente')
GGD.ERR = 201
return
end
-- Gestione tavola macchina
local nMchId = EgtAddMachGroup( 'Mach01')
EgtSetTable( 'Tab')
local tabOri = EgtGetTableRef( 1)
-- Posizionamento delle morse per calcio
local nFix
if bBeretta then
if m_vRaw.dLen < LEN_MAX_ASTA then
nFix = EgtAddFixture( 'ViseH75_ASTA', Vector3d( 600, 345.1, 0), 0, m_vRaw.dAlt * m_dCoeffAlt)
else
nFix = EgtAddFixture( 'ViseH75_CALC', Vector3d( 600, 345.1, 0), 0, m_vRaw.dAlt * m_dCoeffAlt)
end
elseif bMazak then
nFix = EgtAddFixture( 'ViseNew', Vector3d( 350, 250, 0), 0, m_vRaw.dAlt * m_dCoeffAlt)
else
if m_vRaw.dLen < LEN_MIN_RIFLE then
nFix = EgtAddFixture( 'Vise2H85', Vector3d( 629, 350-1.49, 0), 0, m_vRaw.dAlt * m_dCoeffAlt)
else
nFix = EgtAddFixture( 'ViseRifle', Vector3d( 600, 350-1.49, 0), 0, m_vRaw.dAlt * m_dCoeffAlt)
end
end
-- Allargo area utile per movimenti grezzo per non avere problemi nelle fasi intermedie del movimento
EgtSetTableAreaOffset( 500, 500, 500, 500)
-- Posizionamento del grezzo in macchina
local ColA = Color3d( 255, 165, 0, 30)
local nRaw = EgtAddRawPartWithPart( Pz, Sol, 0, ColA) or GDB_ID.NULL
EgtSetStatus( Sol, GDB_ST.ON)
local b3Raw = EgtGetBBoxGlob( Sol, GDB_BB.EXACT)
local ptRawCen = EgtGetRawPartCenter( nRaw)
--EgtOutLog( 'RawBox=' .. tostring( b3Raw))
--EgtOutLog( 'RawCen=' .. tostring( ptRawCen))
local ptPosTL = Point3d( 0, b3Raw:getDimY(), 0)
local bRawPartOk = EgtMoveToCornerRawPart( nRaw, ptPosTL, MCH_CR.TL)
local ptRef = Point3d( b3Raw:getMin():getX() - ptRawCen:getX(), b3Raw:getMax():getY() - ptRawCen:getY(), 0) - vtSolDelta
local ptNewRef = Point3d( ptRef)
for i = 1, #m_vRawRef do
local RawRef = m_vRawRef[i]
if RawRef.Type == 1 then
local vtMove = Point3d( RawRef.dX, RawRef.dY, RawRef.dZ) - ( tabOri + ptPosTL - vtSolDelta)
EgtOutLog( 'MoveRawPart=' .. tostring( vtMove))
if not EgtMoveRawPart( nRaw, Point3d( RawRef.dX, RawRef.dY, RawRef.dZ) - ( tabOri + ptPosTL - vtSolDelta)) then
bRawPartOk = false
end
elseif RawRef.Type == 2 then
local vtAx
if RawRef.sAx == 'X' then
vtAx = X_AX()
elseif RawRef.sAx == 'Y' then
vtAx = Y_AX()
else -- 'Z'
vtAx = Z_AX()
end
if not EgtRotateRawPart( nRaw, vtAx, RawRef.dAng) then
bRawPartOk = false
end
ptNewRef:rotate( ORIG(), vtAx, RawRef.dAng)
end
end
-- per compensare rotazione su centroide anzichè su angolo TL
--EgtOutLog( 'CompRot : ptRef='..tostring( ptRef)..' ptNewRef='..tostring( ptNewRef))
if not EgtMoveRawPart( nRaw, ptRef - ptNewRef) then
bRawPartOk = false
end
if not bRawPartOk then
EGB.WriteErrLine( 'ERR=202\nErrore : in creazione o posizionamento grezzo')
GGD.ERR = 202
return
end
-- Generazione programma principale
if not EGB.OpenOutFile( EgtIf( bMazak, sCncMazFile, sCncFile)) then
EGB.WriteErrLine( 'ERR=203\nErrore nell\'apertura del file cnc ' .. EgtIf( bMazak, sCncMazFile, sCncFile))
GGD.ERR = 203
return
end
-- se macchina Mazak
if bMazak then
-- emissione intestazione
EGB.WriteOutLine( '(' .. EgtGetCurrMachineName():upper() .. ')')
EGB.WriteOutLine( '(' .. sPezName:upper() .. sPezExt:upper() .. '-' .. sModName:upper() .. sModExt:upper() .. ')')
EGB.WriteOutLine( '(' .. GGD.DESCR:upper() .. ')')
EGB.WriteOutLine( '(' .. m_sAttr:upper() .. ')')
-- emissioni iniziali opzionali
local sStart1Def = ''
if m_vRaw.dLen < LEN_MIN_RIFLE then
WriteOutLineFromIni( 'Gunstock', 'Start1', sStart1Def, sMachIni)
else
WriteOutLineFromIni( 'Gunstock', 'Start1_R', sStart1Def, sMachIni)
end
-- emissione inizializzazioni
EGB.WriteOutLine( '')
EGB.WriteOutLine( '(INIZIO)')
EGB.WriteOutLine( '#5241=0')
EGB.WriteOutLine( '#5242=0')
EGB.WriteOutLine( '#5243=0')
EGB.WriteOutLine( '#5244=0')
EGB.WriteOutLine( '#5245=0')
EGB.WriteOutLine( 'G0 G17 G40 G49 G80 G90 G94')
EGB.WriteOutLine( 'G0 G53 Z0')
EGB.WriteOutLine( 'G0 G53 X0')
EGB.WriteOutLine( 'G0 G53 Y0')
EGB.WriteOutLine( 'G0 G53 A0 C0')
EGB.WriteOutLine( 'G61.1')
-- seconde emissioni iniziali opzionali
local sStart2Def = ''
if m_vRaw.dLen < LEN_MIN_RIFLE then
WriteOutLineFromIni( 'Gunstock', 'Start2', sStart2Def, sMachIni)
else
WriteOutLineFromIni( 'Gunstock', 'Start2_R', sStart2Def, sMachIni)
end
-- emissione dei posizionamenti e dei richiami delle lavorazioni
if not EgtSetCalcTool( 'Calc', 'H1', 1) then
EGB.WriteErrLine( 'ERR=204\nErrore nell\'impostazione dell\'utensile di calcolo')
GGD.ERR = 204
return
end
local nNum = 0
local sTcPosPrev
local dPrevR1, dPrevR2 = 9999, 9999
for i = 1, #m_vMachs do
-- lavorazione i-esima
local vMach = m_vMachs[i]
local frMach = EgtFR( vMach.nLay, GDB_ID.ROOT)
-- emissione info di lavorazione
EGB.WriteOutLine( '')
nNum = nNum + 10
if vMach.sInfo then
EGB.WriteOutLine( 'N'..EgtNumToString(nNum,0)..' (' .. vMach.sInfo:upper() .. ')')
else
EGB.WriteOutLine( 'N'..EgtNumToString(nNum,0)..' ( *** )')
end
-- recupero dati utensile
local sTname = EgtGetInfo( vMach.nLay, 'TNAME')
local sTcPos = EgtGetInfo( vMach.nLay, 'TPOS')
if not sTcPos then
EGB.WriteOutLine( '(ERRORE MANCA TPOS IN ' .. vMach.sName .. ')')
EGB.WriteErrLine( 'ERR=211\nErrore manca TPOS in ' .. vMach.sName)
GGD.ERR = 211
return
end
-- se utensile cambiato
local bTdiff = ( sTcPos ~= sTcPosPrev)
if bTdiff then
-- posizionamento prima di cambio utensile
if i > 1 then
EGB.WriteOutLine( 'G0 G53 Z0')
EGB.WriteOutLine( 'G0 G53 Y-1000')
EGB.WriteOutLine( 'G0 G53 X0')
EGB.WriteOutLine( 'G0 G53 Y0')
end
-- emissione richiamo utensile
EGB.WriteOutLine( sTcPos .. ' M6' .. EgtIf( sTname, ' ('..EgtTrim( sTname)..')', ''))
end
-- preselezione prossimo utensile
if i < #m_vMachs then
local sTcPosNext = EgtGetInfo( m_vMachs[i+1].nLay, 'TPOS')
EGB.WriteOutLine( sTcPosNext or 'T0')
else
EGB.WriteOutLine( 'T0')
end
-- emissione speed
local sSpeed = EgtGetInfo( vMach.nLay, 'SPEED')
if not sSpeed then
EGB.WriteOutLine( '(ERRORE MANCA SPEED IN ' .. vMach.sName .. ')')
EGB.WriteErrLine( 'ERR=212\nErrore manca SPEED in ' .. vMach.sName)
GGD.ERR = 212
return
end
EGB.WriteOutLine( sSpeed)
-- se utensile cambiato, posizionamento dopo cambio utensile
if bTdiff then
EGB.WriteOutLine( 'G0 G53 Z0')
EGB.WriteOutLine( 'G0 G53 X0')
EGB.WriteOutLine( 'G0 G53 Y-1000')
end
-- calcolo angoli
local dNearR1, dNearR2 = 0, 0
if vMach.Ang then
dNearR1 = vMach.Ang.dR1
dNearR2 = vMach.Ang.dR2
end
local bRaOk, dR1, dR2 = EGB.GetAngMach( frMach:getVersZ(), dNearR1, dNearR2)
if not bRaOk then
EGB.WriteOutLine( '( ERRORE CALC ROTAX DI ' .. vMach.sName .. ')')
EGB.WriteErrLine( 'ERR=205\nErrore nel calcolo assi rotanti di ' .. vMach.sName)
GGD.ERR = 205
return
else
vMach.Ang.dR1N = dR1
vMach.Ang.dR2N = dR2
dPrevR1 = dR1
dPrevR2 = dR2
EGB.WriteOutLine( 'G55')
-- la posizione rimane inalterata
local dX = frMach:getOrigin():getX()
local dY = frMach:getOrigin():getY()
local dZ = frMach:getOrigin():getZ()
-- calcolo degli angoli di rotazione attorno agli assi fissi
local dA, dB, dC = GetFixedAxesRotABCFromFrame( frMach)
if not dA then
EGB.WriteOutLine( '; ERRORE CALC ANG DI ' .. vMach.sName)
EGB.WriteErrLine( 'ERR=207\nErrore nel calcolo ANG di ' .. vMach.sName)
GGD.Err = 207
return
end
-- emissione
EGB.WriteOutLine( '(ANGOLI ATTESI: A' .. EgtNumToString( dR2, 3) ..
' C' .. EgtNumToString( dR1, 3) ..')')
EGB.WriteOutLine( 'G68.2 P1 Q123 X' .. EgtNumToString( dX, 3) ..
' Y' .. EgtNumToString( dY, 3) ..
' Z' .. EgtNumToString( dZ, 3) ..
' I' .. EgtNumToString( dA, 3) ..
' J' .. EgtNumToString( dB, 3) ..
' K' .. EgtNumToString( dC, 3))
EGB.WriteOutLine( 'G53.1')
EGB.WriteOutLine( 'M98P' .. vMach.sName)
EGB.WriteOutLine( 'G69')
EGB.WriteOutLine( 'G49')
end
-- salvo utensile corrente come prossimo precedente
sTcPosPrev = sTcPos
end
-- emissione terminazione
EGB.WriteOutLine( '')
EGB.WriteOutLine( 'N9999 (FINE)')
EGB.WriteOutLine( 'G0 G53 Z0')
EGB.WriteOutLine( 'G0 G53 Y-1000')
EGB.WriteOutLine( 'G0 G53 X0')
EGB.WriteOutLine( 'G0 G53 Y0')
EGB.WriteOutLine( 'G0 G53 A0 C0')
EGB.WriteOutLine( 'M9')
EGB.WriteOutLine( 'M5')
EGB.WriteOutLine( 'T0 M6')
if #m_vMachs > 0 then
local sTcPosFirst = EgtGetInfo( m_vMachs[1].nLay, 'TPOS')
EGB.WriteOutLine( sTcPosFirst)
end
EGB.WriteOutLine( 'G64')
-- emissioni finali opzionali
-- emissione terminazione
local sEndDef = ''
if m_vRaw.dLen < LEN_MIN_RIFLE then
WriteOutLineFromIni( 'Gunstock', 'End', sEndDef, sMachIni)
else
WriteOutLineFromIni( 'Gunstock', 'End_R', sEndDef, sMachIni)
end
-- terminazione file
EGB.WriteOutLine( 'M30')
-- altrimenti macchina CMS in Beretta (tutto in un solo file)
elseif bBeretta then
-- posizione Origine1 rispetto Zero Macchina (punto intersezione assi rotanti)
local OffsX = -1598.00
local OffsY = -2126.10
local OffsZ = -670.65
-- emissione intestazione
EGB.WriteOutLine( '(DIS,"CODICE=PRG1")')
EGB.WriteOutLine( '; ' .. EgtGetCurrMachineName():upper())
EGB.WriteOutLine( '; ' .. sPezName:upper() .. sPezExt:upper() .. '-' .. sModName:upper() .. sModExt:upper())
EGB.WriteOutLine( '; ' .. GGD.DESCR:upper())
EGB.WriteOutLine( '; ' .. m_sAttr:upper())
local sStart1Def = 'M70<br/>"CICLI"'
if m_vRaw.dLen < LEN_MIN_RIFLE then
WriteOutLineFromIni( 'Gunstock', 'Start1', sStart1Def, sMachIni)
else
WriteOutLineFromIni( 'Gunstock', 'Start1_R', sStart1Def, sMachIni)
end
for i = 1, #m_vParams do
EGB.WriteOutLine( m_vParams[i].sVar .. '=' .. EgtNumToString( m_vParams[i].dVal, 3))
end
local sStart2Def = 'G79G0Z0<br/>G79X0Y0C0B0'
if m_vRaw.dLen < LEN_MIN_RIFLE then
WriteOutLineFromIni( 'Gunstock', 'Start2', sStart2Def, sMachIni)
else
WriteOutLineFromIni( 'Gunstock', 'Start2_R', sStart2Def, sMachIni)
end
EGB.WriteOutLine( '(UAO,0)')
EGB.WriteOutLine( '(UTO,0,X0,Y0,Z0)')
EGB.WriteOutLine( '(TCP)')
EGB.WriteOutLine( '(UPR)')
-- emissione dei posizionamenti e dei richiami delle lavorazioni
if not EgtSetCalcTool( 'Calc', 'H1', 1) then
EGB.WriteErrLine( 'ERR=204\nErrore nell\'impostazione dell\'utensile di calcolo')
GGD.ERR = 204
return
end
local dCalcLen = EgtTdbGetCurrToolParam( MCH_TP.LEN)
local nNum = 0
local dPrevR1, dPrevR2 = 9999, 9999
for i = 1, #m_vMachs do
-- lavorazione i-esima
local vMach = m_vMachs[i]
local frMach = EgtFR( vMach.nLay, GDB_ID.ROOT)
-- emissione info di lavorazione
EGB.WriteOutLine( ';')
nNum = nNum + 10
if vMach.sInfo then
EGB.WriteOutLine( 'N'..EgtNumToString(nNum,0)..' ; ' .. vMach.sInfo:upper())
else
EGB.WriteOutLine( 'N'..EgtNumToString(nNum,0)..' ; ***')
end
-- emissione info utensile
local sToolInfo = ''
local sTcPos = EgtGetInfo( vMach.nLay, 'TCPOS')
if sTcPos == 'T00' then
sToolInfo = sToolInfo .. 'T=PRECEDENTE'
elseif sTcPos then
sToolInfo = sToolInfo .. sTcPos:upper()
end
local sTcomp = EgtGetInfo( vMach.nLay, 'TCOMP')
if sTcomp then sToolInfo = sToolInfo .. ' H' .. sTcomp:upper() end
local sTname = EgtGetInfo( vMach.nLay, 'TNAME')
if sTname then sToolInfo = sToolInfo .. ' ' .. sTname:upper() end
EGB.WriteOutLine( '; ' .. sToolInfo)
-- calcolo angoli
local dNearR1, dNearR2 = 0, 0
if vMach.Ang then
dNearR1 = vMach.Ang.dR1
dNearR2 = vMach.Ang.dR2
end
local bRaOk, dR1, dR2 = EGB.GetAngMach( frMach:getVersZ(), dNearR1, dNearR2)
if not bRaOk then
EGB.WriteOutLine( '; ERRORE CALC ROTAX DI ' .. vMach.sName:upper())
EGB.WriteErrLine( 'ERR=205\nErrore nel calcolo assi rotanti di ' .. vMach.sName)
GGD.ERR = 205
return
else
vMach.Ang.dR1N = dR1
vMach.Ang.dR2N = dR2
if vMach.PrepRot and
( abs( dR1 - dPrevR1) > GEO.EPS_ANG_SMALL or abs( dR2 - dPrevR2) > GEO.EPS_ANG_SMALL) then
local sOut = 'G90G0'..'B'..EgtNumToString( dR1 - vMach.PrepRot.dR1, 3)..
'C'..EgtNumToString( dR2 - vMach.PrepRot.dR2, 3)
EGB.WriteOutLine( sOut)
sOut = 'G90G1'..'B'..EgtNumToString( dR1, 3)..'C'..EgtNumToString( dR2, 3)..
'F'..EgtNumToString( vMach.PrepRot.dFeed, 0)
EGB.WriteOutLine( sOut)
else
local sOut = 'G90G0'..'B'..EgtNumToString( dR1, 3)..'C'..EgtNumToString( dR2, 3)
EGB.WriteOutLine( sOut)
end
dPrevR1 = dR1
dPrevR2 = dR2
EGB.WriteOutLine( '(UAO,1)')
-- calcolo posizione
local bLa1Ok, _, dX1, dY1, dZ1 = EgtGetCalcPositions( frMach:getOrigin(), dR1, dR2)
if not bLa1Ok then
EGB.WriteOutLine( '; ERRORE CALC UTO DI ' .. vMach.sName:upper())
EGB.WriteErrLine( 'ERR=206\nErrore nel calcolo UTO di ' .. vMach.sName)
GGD.Err = 206
return
end
local dX = dX1
local dY = dY1
local dZ = dZ1 - dCalcLen
EGB.WriteOutLine( '(UTO,1,X' .. EgtNumToString( dX - OffsX, 3) ..
',Y' .. EgtNumToString( dY - OffsY, 3) ..
',Z' .. EgtNumToString( dZ - OffsZ, 3) .. ')')
-- calcolo rotazione
local bLa2Ok, _, dX2, dY2, dZ2 = EgtGetCalcPositions( frMach:getOrigin() + 100*frMach:getVersX(), dR1, dR2)
if not bLa2Ok then
EGB.WriteOutLine( '; ERRORE CALC ROT DI ' .. vMach.sName:upper())
EGB.WriteErrLine( 'ERR=207\nErrore nel calcolo ROT di ' .. vMach.sName)
GGD.Err = 207
return
end
local dAng = atan2( dY2 - dY1, dX2 - dX1)
if abs( dZ2 - dZ1) > GEO.EPS_SMALL then
EgtOutLog( 'Differenza sensibile in Z per ROT :'..EgtNumToString( dZ1, 6)..'/'..EgtNumToString( dZ2, 6))
end
EGB.WriteOutLine( 'G17')
EGB.WriteOutLine( '(AXO,-Z)')
EGB.WriteOutLine( '(ROT,' .. EgtNumToString( dAng, 3) .. ')')
EGB.WriteOutLine( '(GTO,SUB' .. vMach.sName .. ')')
EGB.WriteOutLine( '"END' .. vMach.sName .. '"')
EGB.WriteOutLine( '(UAO,0)')
EGB.WriteOutLine( '(ROT,0)')
end
end
-- emissione terminazione
local sEndDef = 'G79G0Z0<br/>G79X0Y0C0B0'
if m_vRaw.dLen < LEN_MIN_RIFLE then
WriteOutLineFromIni( 'Gunstock', 'End', sEndDef, sMachIni)
else
WriteOutLineFromIni( 'Gunstock', 'End_R', sEndDef, sMachIni)
end
EGB.WriteOutLine( 'M30')
-- accodamento subroutines
for i = 1, #m_vMachs do
-- lavorazione i-esima
local vMach = m_vMachs[i]
EGB.WriteOutLine( ';')
EGB.WriteOutLine( '"SUB' .. vMach.sName .. '"')
-- inserisco il corpo della sub
local sSubFile = sSubDir..'SUB'..vMach.sName
local SubFh = io.open( sSubFile, 'r')
if not SubFh then
EGB.WriteErrLine( 'ERR=213\nErrore mancata apertura subroutine '..sSubFile)
GGD.ERR = 213
return
end
local sLine = SubFh:read( '*l')
while sLine do
sLine = EgtTrimRight( sLine)
if #sLine > 0 then
EGB.WriteOutLine( sLine)
end
sLine = SubFh:read( '*l')
end
SubFh:close()
EGB.WriteOutLine( '(GTO,END' .. vMach.sName .. ')')
end
EGB.WriteOutLine( ';')
EGB.WriteOutLine( '; EOF')
-- altrimenti macchine CMS
else
-- emissione intestazione
EGB.WriteOutLine( '(DIS,"CODICE=PRG1")')
EGB.WriteOutLine( '; ' .. EgtGetCurrMachineName():upper())
EGB.WriteOutLine( '; ' .. sPezName:upper() .. sPezExt:upper() .. '-' .. sModName:upper() .. sModExt:upper())
EGB.WriteOutLine( '; ' .. GGD.DESCR:upper())
EGB.WriteOutLine( '; ' .. m_sAttr:upper())
local sStart1Def = 'M70<br/>"CICLI"'
if m_vRaw.dLen < LEN_MIN_RIFLE then
WriteOutLineFromIni( 'Gunstock', 'Start1', sStart1Def, sMachIni)
else
WriteOutLineFromIni( 'Gunstock', 'Start1_R', sStart1Def, sMachIni)
end
for i = 1, #m_vParams do
EGB.WriteOutLine( m_vParams[i].sVar .. '=' .. EgtNumToString( m_vParams[i].dVal, 3))
end
if ( bTwoHeads and #m_vMachs > 0) then
local sTcPos = EgtGetInfo( m_vMachs[1].nLay, 'TCPOS')
if not sTcPos then
EGB.WriteErrLine( 'ERR=208\nErrore non trovata posizione utensile in CU')
GGD.ERR = 208
return
end
local nTcPos = tonumber( sTcPos:sub( 2))
EGB.WriteOutLine( EgtIf( nTcPos <= 18, 'M41M52', 'M42M51'))
EGB.WriteOutLine( sTcPos .. ' M6')
end
local sStart2Def = 'G79G0Z0<br/>G79X-1500Y-1600C0B0'
if m_vRaw.dLen < LEN_MIN_RIFLE then
WriteOutLineFromIni( 'Gunstock', 'Start2', sStart2Def, sMachIni)
else
WriteOutLineFromIni( 'Gunstock', 'Start2_R', sStart2Def, sMachIni)
end
EGB.WriteOutLine( '(UAO,0)')
EGB.WriteOutLine( EgtIf( bTwoHeads, '(UOT,0,X0,U0,Y0,Z0,W0)', '(UOT,0,X0,Y0,Z0)'))
-- emissione dei posizionamenti e dei richiami delle lavorazioni
if not EgtSetCalcTool( 'Calc', 'H1', 1) then
EGB.WriteErrLine( 'ERR=204\nErrore nell\'impostazione dell\'utensile di calcolo')
GGD.ERR = 204
return
end
local dCalcLen = EgtTdbGetCurrToolParam( MCH_TP.LEN)
local nNum = 0
local dPrevR1, dPrevR2 = 9999, 9999
for i = 1, #m_vMachs do
-- lavorazione i-esima
local vMach = m_vMachs[i]
local frMach = EgtFR( vMach.nLay, GDB_ID.ROOT)
-- emissione info di lavorazione
nNum = nNum + 10
if vMach.sInfo then
EGB.WriteOutLine( 'N'..EgtNumToString(nNum,0)..' ; ' .. vMach.sInfo:upper())
else
EGB.WriteOutLine( 'N'..EgtNumToString(nNum,0)..' ; ***')
end
-- emissione info utensile
local sToolInfo = ''
local sTcPos = EgtGetInfo( vMach.nLay, 'TCPOS')
if sTcPos == 'T00' then
sToolInfo = sToolInfo .. 'T=PRECEDENTE'
elseif sTcPos then
sToolInfo = sToolInfo .. sTcPos:upper()
end
local sTcomp = EgtGetInfo( vMach.nLay, 'TCOMP')
if sTcomp then sToolInfo = sToolInfo .. ' H' .. sTcomp:upper() end
local sTname = EgtGetInfo( vMach.nLay, 'TNAME')
if sTname then sToolInfo = sToolInfo .. ' ' .. sTname:upper() end
EGB.WriteOutLine( '; ' .. sToolInfo)
-- calcolo angoli
local dNearR1, dNearR2 = 0, 0
if vMach.Ang then
dNearR1 = vMach.Ang.dR1
dNearR2 = vMach.Ang.dR2
end
local bRaOk, dR1, dR2 = EGB.GetAngMach( frMach:getVersZ(), dNearR1, dNearR2)
if not bRaOk then
EGB.WriteOutLine( '; ERRORE CALC ROTAX DI ' .. vMach.sName:upper())
EGB.WriteErrLine( 'ERR=205\nErrore nel calcolo assi rotanti di ' .. vMach.sName)
GGD.ERR = 205
return
else
vMach.Ang.dR1N = dR1
vMach.Ang.dR2N = dR2
if vMach.PrepRot and
( abs( dR1 - dPrevR1) > GEO.EPS_ANG_SMALL or abs( dR2 - dPrevR2) > GEO.EPS_ANG_SMALL) then
local sOut = 'G90G0'..'B'..EgtNumToString( dR1 - vMach.PrepRot.dR1, 3)..
'C'..EgtNumToString( dR2 - vMach.PrepRot.dR2, 3)
EGB.WriteOutLine( sOut)
sOut = 'G90G1'..'B'..EgtNumToString( dR1, 3)..'C'..EgtNumToString( dR2, 3)..
'F'..EgtNumToString( vMach.PrepRot.dFeed, 0)
EGB.WriteOutLine( sOut)
else
local sOut = 'G90G0'..'B'..EgtNumToString( dR1, 3)..'C'..EgtNumToString( dR2, 3)
EGB.WriteOutLine( sOut)
end
dPrevR1 = dR1
dPrevR2 = dR2
if bTwoHeads then EGB.WriteOutLine( 'G400') end
EGB.WriteOutLine( '(UAO,0)')
-- calcolo posizione
local bLa1Ok, _, dX1, dY1, dZ1 = EgtGetCalcPositions( frMach:getOrigin(), dR1, dR2)
if not bLa1Ok then
EGB.WriteOutLine( '; ERRORE CALC UOT DI ' .. vMach.sName:upper())
EGB.WriteErrLine( 'ERR=206\nErrore nel calcolo UOT di ' .. vMach.sName)
GGD.Err = 206
return
end
local dX = dX1
local dY = dY1
local dZ = dZ1 - dCalcLen
if bTwoHeads then
EGB.WriteOutLine( '(UOT,0,X' .. EgtNumToString( dX, 3) .. ',U' .. EgtNumToString( dX, 3) ..
',Y' .. EgtNumToString( dY, 3) ..
',Z' .. EgtNumToString( dZ, 3) .. ',W' .. EgtNumToString( dZ, 3) .. ')')
else
EGB.WriteOutLine( '(UOT,0,X' .. EgtNumToString( dX, 3) ..
',Y' .. EgtNumToString( dY, 3) ..
',Z' .. EgtNumToString( dZ, 3) .. ')')
end
-- calcolo rotazione
local bLa2Ok, _, dX2, dY2, dZ2 = EgtGetCalcPositions( frMach:getOrigin() + 100*frMach:getVersX(), dR1, dR2)
if not bLa2Ok then
EGB.WriteOutLine( '; ERRORE CALC URT DI ' .. vMach.sName:upper())
EGB.WriteErrLine( 'ERR=207\nErrore nel calcolo URT di ' .. vMach.sName)
GGD.Err = 207
return
end
local dAng = atan2( dY2 - dY1, dX2 - dX1)
if abs( dZ2 - dZ1) > GEO.EPS_SMALL then
EgtOutLog( 'Differenza sensibile in Z per URT :'..EgtNumToString( dZ1, 6)..'/'..EgtNumToString( dZ2, 6))
end
EGB.WriteOutLine( '(URT,' .. EgtNumToString( dAng, 3) .. ')')
EGB.WriteOutLine( '(CLS,SUB' .. vMach.sName .. ')')
EGB.WriteOutLine( '(UAO,0)')
EGB.WriteOutLine( '(URT,0)')
end
end
-- emissione terminazione
local sEndDef = 'G79G0Z0<br/>G79X-500Y-600C0B0<br/>M63<br/>M70<br/>(GTO,CICLI,@SINGOLO=0)'
if m_vRaw.dLen < LEN_MIN_RIFLE then
WriteOutLineFromIni( 'Gunstock', 'End', sEndDef, sMachIni)
else
WriteOutLineFromIni( 'Gunstock', 'End_R', sEndDef, sMachIni)
end
EGB.WriteOutLine( 'M30')
end
-- chiusura file CNC
EGB.CloseOutFile()
-- Inserimento lavorazioni equivalenti
for i = 1, #m_vMachs do
-- lavorazione i-esima
local vMach = m_vMachs[i]
-- aggiungo lavorazione
local MachId = EgtAddMachining( vMach.sName, 'Calc')
if not MachId then
EGB.WriteErrLine( 'ERR=302\nErrore nel caricamento della lavorazione Calc')
GGD.ERR = 302
return
end
-- assegno i percorsi di lavorazione (pescandoli nel layer)
local vGeo = {}
local nId = EgtGetFirstInGroup( vMach.nLay)
while nId do
local nType = EgtGetType( nId)
if nType == GDB_TY.CRV_LINE or nType == GDB_TY.CRV_ARC or
nType == GDB_TY.CRV_BEZ or nType == GDB_TY.CRV_COMPO then
table.insert( vGeo, nId)
end
nId = EgtGetNext( nId)
end
EgtSetMachiningGeometry( vGeo)
-- assegno eventuali Hint sugli angoli
if vMach.Ang then
local sNotes = 'Hint:B=' .. EgtNumToString( vMach.Ang.dR1N, 3) .. ',C=' .. EgtNumToString( vMach.Ang.dR2N, 3) .. ';'
EgtOutLog( sNotes)
EgtSetMachiningParam( MCH_MP.USERNOTES, sNotes)
end
-- applico
-- per ora lascio all'utente
-- la disabilito
EgtSetOperationMode( MachId, false)
end
-- Salvo il progetto
if not EgtSaveFile( sNgeFile) then
EGB.WriteErrLine( 'ERR=301\nErrore nel salvataggio del progetto ' .. sNgeFile)
GGD.ERR = 301
return
end
-- Messaggi di conclusione (con chiusura file errori)
EGB.WriteErrLine( 'ERR=0\nCompletato con successo')
GGD.ERR = 0
end
-----------------------------------------------------------------
-- *** GUNSTOCK copy PartProgram (main + subs) ***
-----------------------------------------------------------------
function GGD.CopyPartProgram()
local bOk = true
local sPezFile = GGD.PEZFILE
local sPezDir, sPezName, sPezExt = EgtSplitPath( sPezFile)
local sBaseDir = sPezDir:sub( 1, -5)
local sCncFile = sBaseDir .. 'CNC\\' .. sPezName
local sDestDir = GGD.COPYDIR
-- Messaggi di inizio
EgtOutLog( 'Pez = ' .. sPezFile .. ' DestDir = ' .. sDestDir)
-- Verifico il direttorio destinazione
if not EgtExistsDirectory( sDestDir) then
GGD.ERR = 401
return
end
-- Copio il file main
if not EgtCopyFile( sCncFile, sDestDir..'\\'..sPezName) then
GGD.ERR = 402
return
end
-- Messaggi di conclusione
EgtOutLog( 'Completato con successo')
GGD.ERR = 0
end