Files
egwwindowlua/CAMAuto/ProcessWin.lua
T
andrea.villa 9d493812d9 - Creazione directoy per CAM Auto
- Creata Process, selezione pezzi manuale (NON FUNZIONANTE)
2024-06-13 10:27:19 +02:00

215 lines
8.2 KiB
Lua

-- Process.lua by Egalware s.r.l. 2024/06/13
-- Gestione calcolo disposizione e lavorazioni per serramenti
-- Si opera sulla macchina corrente
-- 2024/06/13 PRIMA VERSIONE
-- Intestazioni
require( 'EgtBase')
_ENV = EgtProtectGlobal()
EgtEnableDebug( true)
-- TODO da cancellare quando verrà passato automaticamente da programma
local WIN = {}
WIN.BASEDIR = 'C:\\EgtData\\EgwWindowLua\\CAMAuto'
-- Imposto direttorio libreria specializzata per serramenti
EgtAddToPackagePath( WIN.BASEDIR .. '\\LuaLibs\\?.lua')
-- Imposto direttorio strategie. N.B. Le strategie dovranno essere caricate con il nome del direttorio padre
EgtAddToPackagePath( WIN.BASEDIR .. '\\Strategies\\?.lua')
-- Verifico che la macchina corrente sia abilitata per la lavorazione delle Travi
local sMachDir = EgtGetCurrMachineDir()
if not sMachDir then
EgtOutBox( 'Errore nel caricamento della macchina corrente', 'Lavora Serramenti', 'ERROR')
return
end
if not EgtExistsFile( sMachDir .. '\\Window\\WinData.lua') then
EgtOutBox( 'La macchina corrente non è configurata per lavorare serramenti', 'Lavora Serramenti', 'ERROR')
return
end
-- Elimino direttori altre macchine e imposto direttorio macchina corrente per ricerca librerie
EgtRemoveBaseMachineDirFromPackagePath()
EgtAddToPackagePath( sMachDir .. '\\Window\\?.lua')
-- Segnalazione avvio
EgtOutLog( '*** Window Process Start ***', 1)
-- Carico le librerie
_G.package.loaded.WinExec = nil
-- TODO controllare se c'è un modo migliore per resettare librerie delle strategie caricate precedentemente
-- Per ottimizzare potremmo anche ciclare solo fino al numero di strategie raggiunto per il momento.
-- Infatti difficile ci siano 9999 strategie.
-- reset strategie caricate come librerie
for i = 1, 99 do
local IdSTRTemp = EgtReplaceString( tostring( i/10000, 4), '0.', '')
local sLibraryToReload = "STR" .. IdSTRTemp .. "\\STR" .. IdSTRTemp
local sLibraryConfigToReload = sLibraryToReload .. "Config"
if _G.package.loaded[sLibraryToReload] then
_G.package.loaded[sLibraryToReload] = nil
end
if _G.package.loaded[sLibraryConfigToReload] then
_G.package.loaded[sLibraryConfigToReload] = nil
end
end
local WinExec = require( 'WinExec')
-- Variabili globali
PARTS = {}
-------------------------------------------------------------------------------------------------------------
-- *** Recupero i pezzi da processare ***
-------------------------------------------------------------------------------------------------------------
local function MyProcessInputData()
-- Recupero le travi selezionate
local nId = EgtGetFirstSelectedObj()
while nId do
local nPartId = EgtGetParent( EgtGetParent( nId or GDB_ID.NULL) or GDB_ID.NULL)
if nPartId then
local bFound = false
for i = 1, #PARTS do
if PARTS[i].id == nPartId then
bFound = true
break
end
end
if not bFound then
table.insert( PARTS, { nInd = #PARTS + 1, id = nPartId, sName = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))})
end
end
nId = EgtGetNextSelectedObj()
end
if #PARTS == 0 then
EgtOutBox( 'Non sono state selezionati pezzi', 'Lavora Pezzi', 'ERROR')
return false
else
local sOut = ''
for i = 1, #PARTS do
sOut = sOut .. PARTS[i].sName .. ', '
end
sOut = sOut:sub( 1, -3)
EgtOutLog( 'Pezzi selezionati : ' .. sOut, 1)
end
EgtDeselectAll()
return true
end
-------------------------------------------------------------------------------------------------------------
local function GetDataConfig()
-- recupero utensili dal magazzino
WinExec.GetToolsFromDB()
-- TODO da gestire eventuali errori bloccanti
return true
end
-------------------------------------------------------------------------------------------------------------
local function GetDispOffsetFromNotes( nPieceIndex)
local bAllOffsetsAreOk = false
local DispOffset = {}
DispOffset.Phase1 = {}
DispOffset.Phase2 = {}
DispOffset.Phase1.dOffsetY = EgtGetInfo( PIECES[nPieceIndex].id, 'OFFY_1', 'd')
DispOffset.Phase1.dOffsetZ = EgtGetInfo( PIECES[nPieceIndex].id, 'OFFZ_1', 'd')
DispOffset.Phase2.dOffsetY = EgtGetInfo( PIECES[nPieceIndex].id, 'OFFY_2', 'd')
DispOffset.Phase2.dOffsetZ = EgtGetInfo( PIECES[nPieceIndex].id, 'OFFZ_2', 'd')
-- controllo se tutti gli offset sono settati
if DispOffset.Phase1.dOffsetY and DispOffset.Phase1.dOffsetZ and DispOffset.Phase2.dOffsetY and DispOffset.Phase2.dOffsetZ then
bAllOffsetsAreOk = true
end
return bAllOffsetsAreOk
end
-------------------------------------------------------------------------------------------------------------
local function GetDispOffsetFromInput( nPieceIndex)
-- assegno alle stringhe i valori letti, in modo che vengano proposti quelli nel dialogo
local sOffYPh1 = EgtIf( PIECES[nPieceIndex].DispOffset.Phase1.dOffsetY, tostring( PIECES[nPieceIndex].DispOffset.Phase1.dOffsetY), tostring( PIECES[nPieceIndex].dWidth / 2))
local sOffZPh1 = EgtIf( PIECES[nPieceIndex].DispOffset.Phase1.dOffsetZ, tostring( PIECES[nPieceIndex].DispOffset.Phase1.dOffsetZ), '0')
local sOffYPh2 = EgtIf( PIECES[nPieceIndex].DispOffset.Phase2.dOffsetY, tostring( PIECES[nPieceIndex].DispOffset.Phase2.dOffsetY), tostring( PIECES[nPieceIndex].dWidth / 2))
local sOffZPh2 = EgtIf( PIECES[nPieceIndex].DispOffset.Phase2.dOffsetZ, tostring( PIECES[nPieceIndex].DispOffset.Phase2.dOffsetZ), '0')
local vInp = EgtDialogBox( 'Dati di disposizione pezzo: ' .. PIECES[nPieceIndex].sName,
{'Sporgenza laterale FASE1', sOffYPh1}, {'Posizione Z FASE1', sOffZPh1},
{'Sporgenza laterale FASE2', sOffYPh2}, {'Posizione Z FASE2', sOffZPh2})
if not vInp or #vInp == 0 then
return false
end
-- salvo input nei valori che utilizzerò dopo
PIECES[nPieceIndex].DispOffset.Phase1.dOffsetY = tonumber( vInp[1])
PIECES[nPieceIndex].DispOffset.Phase1.dOffsetZ = tonumber( vInp[2])
PIECES[nPieceIndex].DispOffset.Phase2.dOffsetY = tonumber( vInp[3])
PIECES[nPieceIndex].DispOffset.Phase2.dOffsetZ = tonumber( vInp[4])
return true
end
---------------------------------------------------------------------
-- Crea il grezzo che verrà messo in macchina
---------------------------------------------------------------------
local function CreateRawPart( PIECES)
end
-------------------------------------------------------------------------------------------------------------
-- *** Inserimento delle travi nel grezzo ***
-------------------------------------------------------------------------------------------------------------
local function MyProcessPieces()
-- verifico che i pezzi selezionati siano compatibili con la macchina
WinData.VerifyPieces( PIECES)
-- si crea il grezzo
CreateRawPart( PIECES)
-- recupero offset per posizionamento
for i = 1, #PIECES do
local bInsertedAllOffs = GetDispOffsetFromNotes( i)
-- se non sono settati nelle note, li chiedo
if not bInsertedAllOffs then
bInsertedAllOffs = GetDispOffsetFromInput( i)
end
-- se non sono stati inseriti o c'è stato un errore esco subito
if not bInsertedAllOffs then
return false
end
end
-- si dispongono i pezzi sulla tavola
WinData.DisposePiecesOnTable( PIECES)
return true
end
-------------------------------------------------------------------------------------------------------------
-- *** Inserimento delle lavorazioni ***
-------------------------------------------------------------------------------------------------------------
local function MyProcessFeatures()
local bOk, Stats = WinExec.ProcessFeatures( PARTS)
return true
end
-------------------------------------------------------------------------------------------------------------
-- *** Esecuzione ***
-------------------------------------------------------------------------------------------------------------
if not MyProcessInputData() then return end
if not MyProcessPieces() then return end
if not GetDataConfig() then return end
-- Abilito Vmill
EgtSetInfo( EgtGetCurrMachGroup(), 'Vm', '1')
if not MyProcessFeatures() then return end