Gunstock :
- modifiche Beretta per import Fagor - correzione per variabili con nomi contenuti in nomi di altre (@A e @ANG).
This commit is contained in:
+155
-36
@@ -1,4 +1,4 @@
|
||||
-- CncFagorToModCncOsai.lua by Egaltech s.r.l. 2022/07/08
|
||||
-- CncFagorToModCncOsai.lua by Egaltech s.r.l. 2022/07/15
|
||||
-- Conversione CNC Fagor in Modello + CNC Osai
|
||||
|
||||
-- Intestazioni
|
||||
@@ -6,22 +6,45 @@ require( 'EgtBase')
|
||||
_ENV = EgtProtectGlobal()
|
||||
EgtEnableDebug( false)
|
||||
|
||||
-----------------------------------------------------------------
|
||||
-- Se espressione
|
||||
local function AdjustExpression( sExpr, vPar)
|
||||
for i = 1, #vPar do
|
||||
sExpr = sExpr:gsub( vPar[i][1], vPar[i][2])
|
||||
end
|
||||
sExpr = sExpr:gsub( 'V.P.', '@')
|
||||
sExpr = sExpr:gsub( '%[', '(')
|
||||
sExpr = sExpr:gsub( '%]', ')')
|
||||
sExpr = sExpr:gsub( 'SQRT', 'sqrt')
|
||||
sExpr = sExpr:gsub( 'SQR', 'sqr')
|
||||
sExpr = sExpr:gsub( 'ASIN', 'asin')
|
||||
sExpr = sExpr:gsub( 'ACOS', 'acos')
|
||||
sExpr = sExpr:gsub( 'ATAN', 'atan')
|
||||
sExpr = sExpr:gsub( 'SIN', 'sin')
|
||||
sExpr = sExpr:gsub( 'COS', 'cos')
|
||||
sExpr = sExpr:gsub( 'TAN', 'tan')
|
||||
return sExpr
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
-- Se linea MOD
|
||||
local function AdjustModLine( sLine)
|
||||
local function AdjustModLine( sLine, vPar)
|
||||
-- analisi linea originale
|
||||
local vsTok = EgtSplitStringPlus( sLine, 'GXYZBUFMK;')
|
||||
local nG, dX, dY, dZ, dB, dU, nF, nM
|
||||
local vsTok = EgtSplitString( sLine, ' ')
|
||||
local nG, sX, sY, sZ, dB, dU, nF, nM
|
||||
for i = 1, #vsTok do
|
||||
local sId = string.sub( vsTok[i], 1, 1)
|
||||
if sId == 'G' then
|
||||
nG = tonumber( string.sub( vsTok[i], 2))
|
||||
elseif sId == 'X' then
|
||||
dX = tonumber( string.sub( vsTok[i], 2))
|
||||
sX = string.sub( vsTok[i], 2)
|
||||
sX = AdjustExpression( sX, vPar)
|
||||
elseif sId == 'Y' then
|
||||
dY = tonumber( string.sub( vsTok[i], 2))
|
||||
sY = string.sub( vsTok[i], 2)
|
||||
sY = AdjustExpression( sY, vPar)
|
||||
elseif sId == 'Z' then
|
||||
dZ = tonumber( string.sub( vsTok[i], 2))
|
||||
sZ = string.sub( vsTok[i], 2)
|
||||
sZ = AdjustExpression( sZ, vPar)
|
||||
elseif sId == 'B' then
|
||||
dB = tonumber( string.sub( vsTok[i], 2))
|
||||
elseif sId == 'U' then
|
||||
@@ -37,22 +60,22 @@ local function AdjustModLine( sLine)
|
||||
-- nuova linea
|
||||
local sNewLine = ''
|
||||
if nG == 181 then
|
||||
sNewLine = ' #TRAS X '..EgtNumToString( dX or 0, 3)..' Y '..EgtNumToString( dY or 0, 3)..' Z '..EgtNumToString( dZ or 0, 3)
|
||||
sNewLine = ' #TRAS X '..( sX or '0')..' Y '..( sY or '0')..' Z '..( sZ or '0')
|
||||
elseif nG == 182 then
|
||||
sNewLine = ' #ROTAZ '
|
||||
local sAx, dRot
|
||||
if dX then
|
||||
local sAx, sRot
|
||||
if sX then
|
||||
sAx = 'X'
|
||||
dRot = dX or 0
|
||||
elseif dY then
|
||||
sRot = sX
|
||||
elseif sY then
|
||||
sAx = 'Y'
|
||||
dRot = dY or 0
|
||||
elseif dZ then
|
||||
sRot = sY
|
||||
elseif sZ then
|
||||
sAx = 'Z'
|
||||
dRot = dZ or 0
|
||||
sRot = sZ
|
||||
end
|
||||
local sMF = EgtIf( nF == 1, ' F ', ' M ')
|
||||
sNewLine = sNewLine .. ( sAx or 'QQQ') .. sMF .. EgtNumToString( dRot or 0, 3)
|
||||
sNewLine = sNewLine .. ( sAx or 'QQQ') .. sMF .. ( sRot or '0')
|
||||
elseif nG == 184 then
|
||||
sNewLine = ' #ANG ' .. EgtNumToString( dB or 0, 3) .. ' ' .. EgtNumToString( dU or 0, 3)
|
||||
elseif nG == 185 then
|
||||
@@ -87,16 +110,25 @@ end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
-- Se linea con movimento, la sistemo e restituisco eventuali nuove quote X e Y
|
||||
local function AdjustMoveLine( sLine, dXp, dYp, nT)
|
||||
local function AdjustMoveLine( sLine, dXp, dYp, nCp, nT)
|
||||
-- analisi linea originale
|
||||
local vsTok = EgtSplitStringPlus( sLine, 'GXYZIJRDFM;')
|
||||
local nG, dX, dY, dI, dJ, nD
|
||||
local nIndI, nIndJ, nIndD
|
||||
local nG, nComp, dX, dY, dI, dJ, nD
|
||||
local nIndG, nIndComp, nIndI, nIndJ, nIndD
|
||||
nComp = nCp
|
||||
for i = 1, #vsTok do
|
||||
local sId = string.sub( vsTok[i], 1, 1)
|
||||
if sId == 'G' then
|
||||
local nVal = tonumber( string.sub( vsTok[i], 2))
|
||||
if nVal and nVal >= 0 and nVal <= 3 then nG = nVal end
|
||||
if nVal then
|
||||
if nVal >= 0 and nVal <= 3 then
|
||||
nIndG = i
|
||||
nG = nVal
|
||||
elseif nVal >= 40 and nVal <= 42 then
|
||||
nIndComp = i
|
||||
nComp = nVal
|
||||
end
|
||||
end
|
||||
elseif sId == 'X' then
|
||||
dX = tonumber( string.sub( vsTok[i], 2))
|
||||
elseif sId == 'Y' then
|
||||
@@ -114,6 +146,11 @@ local function AdjustMoveLine( sLine, dXp, dYp, nT)
|
||||
break
|
||||
end
|
||||
end
|
||||
-- se compensazione su linea con movimento la lascio
|
||||
if dX or dY then
|
||||
nIndComp = nil
|
||||
nComp = nil
|
||||
end
|
||||
-- nuova linea
|
||||
local sNewLine = ''
|
||||
if nG and nG >= 0 and nG <= 3 then
|
||||
@@ -122,7 +159,13 @@ local function AdjustMoveLine( sLine, dXp, dYp, nT)
|
||||
sNewLine = 'h' .. EgtNumToString( nCorr) .. '\n'
|
||||
end
|
||||
for i = 1, #vsTok do
|
||||
if i == nIndI and dI then
|
||||
if i == nIndG then
|
||||
sNewLine = sNewLine .. vsTok[i]
|
||||
if nCp then
|
||||
sNewLine = sNewLine .. 'G' .. EgtNumToString( nCp, 0) .. ' '
|
||||
if nComp == nCp then nComp = nil end
|
||||
end
|
||||
elseif i == nIndI and dI then
|
||||
sNewLine = sNewLine .. 'I' .. EgtNumToString( dI + dXp, 3) .. ' '
|
||||
if not nIndJ then
|
||||
sNewLine = sNewLine .. 'J' .. EgtNumToString( dYp, 3) .. ' '
|
||||
@@ -134,6 +177,8 @@ local function AdjustMoveLine( sLine, dXp, dYp, nT)
|
||||
sNewLine = sNewLine .. 'J' .. EgtNumToString( dJ + dYp, 3) .. ' '
|
||||
elseif i == nIndD then
|
||||
;
|
||||
elseif i == nIndComp then
|
||||
;
|
||||
else
|
||||
sNewLine = sNewLine .. vsTok[i]
|
||||
end
|
||||
@@ -141,18 +186,42 @@ local function AdjustMoveLine( sLine, dXp, dYp, nT)
|
||||
elseif nIndD then
|
||||
local nCorr = EgtIf( nD ==1, nT, 100 + nT)
|
||||
sNewLine = 'h' .. EgtNumToString( nCorr) .. '\n'
|
||||
if nCp and ( dX or dY) then
|
||||
sNewLine = sNewLine .. 'G' .. EgtNumToString( nCp, 0) .. ' '
|
||||
if nComp == nCp then nComp = nil end
|
||||
end
|
||||
for i = 1, #vsTok do
|
||||
if i == nIndD then
|
||||
;
|
||||
elseif i == nIndComp then
|
||||
;
|
||||
else
|
||||
sNewLine = sNewLine .. vsTok[i]
|
||||
end
|
||||
end
|
||||
elseif nIndComp then
|
||||
if nCp and ( dX or dY) then
|
||||
sNewLine = sNewLine .. 'G' .. EgtNumToString( nCp, 0) .. ' '
|
||||
if nComp == nCp then nComp = nil end
|
||||
end
|
||||
for i = 1, #vsTok do
|
||||
if i == nIndComp then
|
||||
;
|
||||
else
|
||||
sNewLine = sNewLine .. vsTok[i]
|
||||
end
|
||||
end
|
||||
elseif dX or dY then
|
||||
if nCp then
|
||||
sNewLine = sNewLine .. 'G' .. EgtNumToString( nCp, 0) .. ' '
|
||||
if nComp == nCp then nComp = nil end
|
||||
end
|
||||
sNewLine = sNewLine..sLine
|
||||
else
|
||||
sNewLine = sLine
|
||||
end
|
||||
|
||||
return sNewLine, dX, dY
|
||||
return sNewLine, dX, dY, nComp
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
@@ -192,20 +261,31 @@ end
|
||||
local nType = 0 -- 0 = inutile, 1 per MOD, 2 per CNC
|
||||
local nModFlag = 0 -- 0 = non definito, 1 = riferimenti, 2 = lavorazioni
|
||||
local nCntTras = 0 -- conteggio traslazioni in riferimenti
|
||||
local vPar = {}
|
||||
local nT
|
||||
local nComp
|
||||
local bHsc
|
||||
local dXp, dYp
|
||||
local sLine = SouFh:read( '*l')
|
||||
while sLine do
|
||||
sLine = EgtTrim( sLine)
|
||||
local nSubType = 0 -- 0 = intermedio, 1 = inizio, 2 = fine
|
||||
if string.find( sLine, '%L SET_RIFERIMENTO', 1, true) then
|
||||
if string.find( sLine, ';#NOME', 1, true) then
|
||||
nType = 1
|
||||
nSubType = 1
|
||||
nModFlag = 1
|
||||
elseif string.find( sLine, '%PRG', 1, true) then
|
||||
elseif string.find( sLine, '%L SET_PARAMETRI', 1, true) then
|
||||
nType = 1
|
||||
nSubType = 1
|
||||
nModFlag = 2
|
||||
elseif string.find( sLine, '%L SET_RIFERIMENTO_LAV1', 1, true) then
|
||||
nType = 1
|
||||
nSubType = 1
|
||||
nModFlag = 3
|
||||
elseif string.find( sLine, '%PRG', 1, true) then
|
||||
nType = 1
|
||||
nSubType = 1
|
||||
nModFlag = 4
|
||||
elseif string.find( sLine, '%L SUB', 1, true) then
|
||||
nType = 2
|
||||
nSubType = 1
|
||||
@@ -218,12 +298,14 @@ while sLine do
|
||||
-- inizio
|
||||
if nSubType == 1 then
|
||||
if nModFlag == 1 then
|
||||
-- Intestazione del modello
|
||||
ModFh:write( '------------ Sezione 1 : dichiarazione nome del modello\n\n')
|
||||
ModFh:write( '#NOME '.. sName..'\n\n')
|
||||
ModFh:write( '#MACH MAT5517\n\n')
|
||||
ModFh:write( '#ATTR attrezzaggio di prova\n\n')
|
||||
ModFh:write( '#ATTR attrezzaggio\n\n')
|
||||
ModFh:write( '---------------- Sezione 2 : dichiarazione lavorazioni piane fase 1\n\n')
|
||||
elseif nModFlag == 2 then
|
||||
ModFh:write( '#END_PAR\n\n')
|
||||
elseif nModFlag == 3 then
|
||||
ModFh:write( '#END_VAR\n\n')
|
||||
ModFh:write( ' #LUNG_GREZZO 275\n')
|
||||
ModFh:write( ' #LARG_GREZZO 60\n')
|
||||
@@ -236,17 +318,37 @@ while sLine do
|
||||
end
|
||||
-- fine
|
||||
elseif nSubType == 2 then
|
||||
if nModFlag == 1 then
|
||||
if nModFlag == 2 then
|
||||
sLine = ''
|
||||
elseif nModFlag == 3 then
|
||||
sLine = ' #END_RIF\n'
|
||||
elseif nModFlag == 2 then
|
||||
elseif nModFlag == 4 then
|
||||
sLine = '#END_PIA_1\n'
|
||||
end
|
||||
ModFh:write( sLine .. '\n')
|
||||
if #sLine > 0 then
|
||||
ModFh:write( sLine .. '\n')
|
||||
end
|
||||
nType = 0
|
||||
-- intermedio
|
||||
else
|
||||
-- se linea dichiarazione parametro
|
||||
if sLine:sub( 1, 7) == ';#PARAM' then
|
||||
local vsTok = EgtSplitString( sLine, ' ')
|
||||
if #vsTok >= 6 then
|
||||
table.insert( vPar, { vsTok[6], '@'..vsTok[2]})
|
||||
else
|
||||
EgtOutLog( 'Linea '..sLine..'con campi in numero insufficiente')
|
||||
end
|
||||
sLine = sLine:gsub( 'P1', 'E')
|
||||
sLine = ' '..sLine:sub( 2)
|
||||
-- se linea dichiarazione variabile
|
||||
elseif sLine:sub( 1, 4) == 'V.P.' then
|
||||
sLine = sLine:sub( 5)
|
||||
sLine = sLine:gsub( '=', '')
|
||||
sLine = AdjustExpression( sLine, vPar)
|
||||
sLine = ' #VAR '..sLine
|
||||
-- se linea di commento speciale, la elimino
|
||||
if sLine:sub( 1, 2) == ';#' then
|
||||
elseif sLine:sub( 1, 2) == ';#' then
|
||||
sLine = ''
|
||||
-- se inizio richiamo lavorazione
|
||||
elseif sLine:sub( 1, 17) == '; Esecuzione: SUB' then
|
||||
@@ -260,8 +362,8 @@ while sLine do
|
||||
-- altrimenti la interpreto
|
||||
else
|
||||
local nG
|
||||
sLine, nG = AdjustModLine( sLine)
|
||||
if nModFlag == 1 and nG == 181 then
|
||||
sLine, nG = AdjustModLine( sLine, vPar)
|
||||
if nModFlag == 3 and nG == 181 then
|
||||
nCntTras = nCntTras + 1
|
||||
if nCntTras == 1 then
|
||||
sLine = sLine .. '\n #END_RIF\n\n #RIF_FUCILE'
|
||||
@@ -282,6 +384,11 @@ while sLine do
|
||||
CncFh:write( '%\n')
|
||||
-- fine
|
||||
elseif nSubType == 2 then
|
||||
-- se attivo comando alta velocità, devo disabilitarlo
|
||||
if bHsc then
|
||||
bHsc = false
|
||||
CncFh:write( '#G355 H3\n')
|
||||
end
|
||||
CncFh:write( '%\n')
|
||||
nType = 0
|
||||
-- intermedio
|
||||
@@ -289,7 +396,16 @@ while sLine do
|
||||
-- se linea di commento
|
||||
if sLine:sub( 1, 1) == ';' then
|
||||
;
|
||||
-- altrimenti
|
||||
-- se linea con comando alta velocità
|
||||
elseif sLine:sub( 1, 4) == '#HSC' then
|
||||
if sLine:find( 'ON', 1, true) then
|
||||
bHsc = true
|
||||
sLine = '#G355 H5'
|
||||
else
|
||||
bHsc = false
|
||||
sLine = '#G355 H3'
|
||||
end
|
||||
-- altrimenti
|
||||
else
|
||||
-- sostituzioni preliminari
|
||||
sLine = sLine:gsub( 'G187', 'G79')
|
||||
@@ -300,8 +416,11 @@ while sLine do
|
||||
sLine = sLine:gsub( 'T31', 'T11')
|
||||
sLine = sLine:gsub( 'T32', 'T18')
|
||||
sLine = sLine:gsub( 'T33', 'T17')
|
||||
-- se linea con richiamo utensile
|
||||
if sLine:find( 'M06', 1, true) or sLine:find( 'M6', 1, true) then
|
||||
-- se linea con arresto utensile
|
||||
if sLine:find( 'M05', 1, true) or sLine:find( 'M5', 1, true) then
|
||||
sLine = 'M05'
|
||||
-- se altrimenti linea con richiamo utensile
|
||||
elseif sLine:find( 'M06', 1, true) or sLine:find( 'M6', 1, true) then
|
||||
local nNewT
|
||||
sLine, nNewT = AdjustToolLine( sLine)
|
||||
if nNewT then nT = nNewT end
|
||||
@@ -309,7 +428,7 @@ while sLine do
|
||||
else
|
||||
-- sistemo dati di movimento (I e J di archi da relativo ad assoluto)
|
||||
local dNewX, dNewY
|
||||
sLine, dNewX, dNewY = AdjustMoveLine( sLine, dXp, dYp, nT)
|
||||
sLine, dNewX, dNewY, nComp = AdjustMoveLine( sLine, dXp, dYp, nComp, nT)
|
||||
if dNewX then dXp = dNewX end
|
||||
if dNewY then dYp = dNewY end
|
||||
end
|
||||
|
||||
+3
-1
@@ -5,5 +5,7 @@ ReadModFun=GGD.ReadModParams()
|
||||
ReadPezFun=GGD.ReadPezParams()
|
||||
WritePezFun=GGD.WritePezParams()
|
||||
CreateFun=GGD.CreateGunstock()
|
||||
CopyFun=GGD.CopyPartProgram()
|
||||
ModDir=
|
||||
PezDir=
|
||||
PezDir=
|
||||
CopyDir=
|
||||
@@ -1,4 +1,4 @@
|
||||
-- Main.lua by Egaltech s.r.l. 2022/07/07
|
||||
-- Main.lua by Egaltech s.r.l. 2022/07/15
|
||||
-- Main gestione lavorazioni Gunstock
|
||||
|
||||
-- Intestazioni
|
||||
@@ -99,7 +99,7 @@ local function GetVars()
|
||||
local Var = {}
|
||||
Var.sName = vsTok[1]
|
||||
Var.sExpr = vsTok[2]
|
||||
Var.dVal = 0
|
||||
Var.dVal = nil
|
||||
table.insert( m_vVars, Var)
|
||||
sLine = EGB.GetLine()
|
||||
if not sLine then return false end
|
||||
@@ -370,10 +370,12 @@ local function EvaluateExpr( sExpr)
|
||||
-- sostituzione valori delle variabili
|
||||
for i = 1, #m_vVars do
|
||||
local Var = m_vVars[i]
|
||||
if Var.dVal >= 0 then
|
||||
sTmp = sTmp:gsub( '@'..Var.sName, EgtNumToString( Var.dVal, 3))
|
||||
else
|
||||
sTmp = sTmp:gsub( '@'..Var.sName, '('..EgtNumToString( Var.dVal, 3)..')')
|
||||
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
|
||||
@@ -397,6 +399,7 @@ 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
|
||||
@@ -404,6 +407,16 @@ local function EvaluateVars()
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user