-- 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( false) -- TODO da cancellare quando verrà passato automaticamente da programma local WIN = {} WIN.BASEDIR = 'C:\\EgtData\\Window\\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 finestre 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.WinData = nil _G.package.loaded.WinExec = nil _G.package.loaded.WinLib = nil _G.package.loaded.FeatureData = nil _G.package.loaded.MachiningLib = nil local WinExec = require( 'WinExec') local PartData = require( 'PartData') -- Carico i dati globali local WinData = require( 'WinData') -- Variabili globali PARTS = {} -- Colore del grezzo local ColA = Color3d( 255, 165, 0, 30) ------------------------------------------------------------------------------------------------------------- -- *** Recupero i pezzi da processare *** ------------------------------------------------------------------------------------------------------------- local function MyProcessInputData() -- Recupero i pezzi selezionati 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 PartData.GetDimensionPart( PARTS) EgtDeselectAll() return true end ------------------------------------------------------------------------------------------------------------- local function GetDataConfig() -- recupero utensili dal magazzino WinExec.GetToolsFromDB() -- TODO da gestire eventuali errori bloccanti return true end ------------------------------------------------------------------------------------------------------------- local function GetDispOffsetFromInput( nPieceIndex) -- assegno alle stringhe i valori letti, in modo che vengano proposti quelli nel dialogo local sOffYPh1 = EgtIf( PARTS[nPieceIndex].DispOffsets.Phase1.dOffsetY, tostring( PARTS[nPieceIndex].DispOffsets.Phase1.dOffsetY), tostring( PARTS[nPieceIndex].dPartWidth / 2)) local sOffZPh1 = EgtIf( PARTS[nPieceIndex].DispOffsets.Phase1.dOffsetZ, tostring( PARTS[nPieceIndex].DispOffsets.Phase1.dOffsetZ), '0') local sOffYPh2 = EgtIf( PARTS[nPieceIndex].DispOffsets.Phase2.dOffsetY, tostring( PARTS[nPieceIndex].DispOffsets.Phase2.dOffsetY), tostring( PARTS[nPieceIndex].dPartWidth / 2)) local sOffZPh2 = EgtIf( PARTS[nPieceIndex].DispOffsets.Phase2.dOffsetZ, tostring( PARTS[nPieceIndex].DispOffsets.Phase2.dOffsetZ), '0') local vInp = EgtDialogBox( 'Dati di disposizione pezzo: ' .. PARTS[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 PARTS[nPieceIndex].DispOffsets.Phase1.dOffsetY = tonumber( vInp[1]) PARTS[nPieceIndex].DispOffsets.Phase1.dOffsetZ = tonumber( vInp[2]) PARTS[nPieceIndex].DispOffsets.Phase2.dOffsetY = tonumber( vInp[3]) PARTS[nPieceIndex].DispOffsets.Phase2.dOffsetZ = tonumber( vInp[4]) return true end --------------------------------------------------------------------- -- Crea il grezzo che verrà messo in macchina --------------------------------------------------------------------- local function CreateRaws( PARTS) for i = 1, #PARTS do -- si crea un grezzo "finto" (un cubo da 100mm) nell'origine del pezzo, verrà poi dimensionato uan volta adeguato con i vari sovramateriali PARTS[i].idRaw = EgtAddRawPart( PARTS[i].frame:getOrigin(), 100, 100, 100, ColA) EgtAddPartToRawPart( PARTS[i].id, ORIG(), PARTS[i].idRaw) end end --------------------------------------------------------------------- -- Allinea i pezzi in base a come devono essere disposti sulla tavola --------------------------------------------------------------------- -- TODO in questa fase bisogna già sapere qual è la prima fase e posizionare il pezzo di conseguenza -- TODO (bassa priorità) adesso allinea sempre in X, ma bisognerebbe farlo in base ad un parametro in WINDATA che dice come si dispongono in macchina local function AlignRawsToTable( PARTS) for i = 1, #PARTS do -- allineo il pezzo all'interno del grezzo local dRotX, dRotY, dRotZ = GetFixedAxesRotABCFromFrame( PARTS[i].frame) -- se devo ruotare if abs( dRotZ) > GEO.EPS_ANG_SMALL then EgtRotatePartInRawPart( PARTS[i].id, Z_AX(), -dRotZ) end -- sposto punto in basso a sinistra del pezzo sul punto in basso a sinistra del grezzo local b3Part = EgtGetBBoxGlob( PARTS[i].id, GDB_BB.ONLY_VISIBLE) local dPartPosX = b3Part:getMin():getX() local dPartPosY = b3Part:getMin():getY() local dPartPosZ = b3Part:getMin():getZ() local b3Raw = EgtGetRawPartBBox( PARTS[i].idRaw) local dRawPosX = b3Raw:getMin():getX() local dRawPosY = b3Raw:getMin():getY() local dRawPosZ = b3Raw:getMin():getZ() local vtMove = Vector3d( dRawPosX - dPartPosX, dRawPosY - dPartPosY, dRawPosZ - dPartPosZ) EgtMovePartInRawPart( PARTS[i].id, vtMove) end return true end ------------------------------------------------------------------------------------------------------------- -- *** Funzione per trovare nome MachGroup *** ------------------------------------------------------------------------------------------------------------- local function NewMachGroupName() local nMachGroupId = EgtGetFirstMachGroup() if not nMachGroupId then return '1' end local nMaxMachGroup = 0 while nMachGroupId do local sMachGroupName = EgtGetMachGroupName( nMachGroupId) local nMachGroupName = tonumber( sMachGroupName) if nMachGroupName > nMaxMachGroup then nMaxMachGroup = nMachGroupName end nMachGroupId = EgtGetNextMachGroup( nMachGroupId) end return tostring( nMaxMachGroup + 1) end ------------------------------------------------------------------------------------------------------------- -- *** Inserimento dei pezzi nel grezzo *** ------------------------------------------------------------------------------------------------------------- local function MyProcessPieces() -- creo macchinata local MachGroupName = NewMachGroupName() local nMachGroup = EgtAddMachGroup( MachGroupName) -- si crea il grezzo CreateRaws( PARTS) -- allineo i pezzi come orientamento richiesto dalla macchina AlignRawsToTable( PARTS) -- aggiungo sovramateriale ai grezzi PartData.AddOverMaterialToRaw( PARTS) -- recupero offset per posizionamento for i = 1, #PARTS do PARTS[i].DispOffsets = {} PARTS[i].DispOffsets.Phase1 = {} PARTS[i].DispOffsets.Phase2 = {} local bInsertedAllOffs = PartData.GetDispOffsetFromNotes( PARTS, 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 local bDispOk, sErr = WinData.ExecDisposition( PARTS) if not bDispOk then if not sErr then sErr = 'Errore non gestito in WinData.ExecDisposition' end EgtOutBox( sErr, 'ProcessWin', 'ERROR', 'OK') return false end -- Impostazione dell'attrezzaggio di default local bOk = EgtImportSetup() if not bOk then EgtImportSetup( 'Default') end return true end ------------------------------------------------------------------------------------------------------------- -- *** Inserimento delle lavorazioni *** ------------------------------------------------------------------------------------------------------------- local function MyProcessFeatures() local bOk = WinExec.ProcessFeatures( PARTS) return true end ------------------------------------------------------------------------------------------------------------- -- *** Esecuzione *** ------------------------------------------------------------------------------------------------------------- -- nascondo geometrie varie local vAuxId = { EgtGetFirstNameInGroup( GDB_ID.ROOT, 'Profile'), EgtGetFirstNameInGroup( GDB_ID.ROOT, 'Area*'), EgtGetFirstNameInGroup( GDB_ID.ROOT, 'Aux')} EgtSetStatus( vAuxId, GDB_ST.OFF) 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