2c1d4ee259
- Aggiunte funzioni Lua per ottimizzazione ordine delle lavorazioni.
247 lines
8.2 KiB
C++
247 lines
8.2 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2025-2025
|
|
//----------------------------------------------------------------------------
|
|
// File : LUA_MachOpt.cpp Data : 02.04.25 Versione : 2.7c1
|
|
// Contenuto : Funzioni per Ottimizzare i tempi tra le lavorazioni per LUA.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 02.04.25 RE Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LUA.h"
|
|
#include "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EGkLuaAux.h"
|
|
#include "/EgtDev/Include/EGnStringUtils.h"
|
|
|
|
using namespace std ;
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaOptMachInit( lua_State* L)
|
|
{
|
|
// Nessun parametro
|
|
LuaClearStack( L) ;
|
|
// Inizializzo il calcolatore per minimizzare i tempi tra le lavorazioni
|
|
bool bOk = ExeOptMachInit() ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaOptMachTerminate( lua_State* L)
|
|
{
|
|
// Nessun parametro
|
|
LuaClearStack( L) ;
|
|
// Termino il calcolatore per minimizzare i tempi tra le lavorazioni
|
|
bool bOk = ExeOptMachTerminate() ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaOptMachAddTool( lua_State* L)
|
|
{
|
|
// Definizione 15 parametri
|
|
int nId = 0 ;
|
|
LuaCheckParam( L, 1, nId) ;
|
|
double dTC_X = 0. ; double dTC_Y = 0. ; double dTC_Z = 0. ;
|
|
LuaCheckParam( L, 2, dTC_X) ;
|
|
LuaCheckParam( L, 3, dTC_Y) ;
|
|
LuaCheckParam( L, 4, dTC_Z) ;
|
|
double dTC_A = 0. ; double dTC_B = 0. ; double dTC_C = 0. ;
|
|
LuaCheckParam( L, 5, dTC_A) ;
|
|
LuaCheckParam( L, 6, dTC_B) ;
|
|
LuaCheckParam( L, 7, dTC_C) ;
|
|
bool bTC_X = false ; bool bTC_Y = false ; bool bTC_Z = false ;
|
|
LuaCheckParam( L, 8, bTC_X) ;
|
|
LuaCheckParam( L, 9, bTC_Y) ;
|
|
LuaCheckParam( L, 10, bTC_Z) ;
|
|
bool bTC_A = false ; bool bTC_B = false ; bool bTC_C = false ;
|
|
LuaCheckParam( L, 11, bTC_A) ;
|
|
LuaCheckParam( L, 12, bTC_B) ;
|
|
LuaCheckParam( L, 13, bTC_C) ;
|
|
double dTLoad = 0. ; double dTUnload = 0. ;
|
|
LuaCheckParam( L, 14, dTLoad) ;
|
|
LuaCheckParam( L, 15, dTUnload) ;
|
|
LuaClearStack( L) ;
|
|
// Aggiungo la Lavorazione
|
|
bool bOk = ExeOptMachAddTool( nId, dTC_X, dTC_Y, dTC_Z, dTC_A, dTC_B, dTC_C,
|
|
bTC_X, bTC_Y, bTC_Z, bTC_A, bTC_B, bTC_C,
|
|
dTLoad, dTUnload) ;
|
|
// Rstituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaOptMachAddMachining( lua_State* L)
|
|
{
|
|
// Definizione 15 parametri
|
|
int nId = 0 ; int nToolId = 0 ; int nGroup = 0 ;
|
|
LuaCheckParam( L, 1, nId) ;
|
|
LuaCheckParam( L, 2, nToolId) ;
|
|
LuaCheckParam( L, 3, nGroup) ;
|
|
double dX_Start = 0. ; double dY_Start = 0. ; double dZ_Start = 0. ;
|
|
double dA_Start = 0. ; double dB_Start = 0. ; double dC_Start = 0. ;
|
|
LuaCheckParam( L, 4, dX_Start) ;
|
|
LuaCheckParam( L, 5, dY_Start) ;
|
|
LuaCheckParam( L, 6, dZ_Start) ;
|
|
LuaCheckParam( L, 7, dA_Start) ;
|
|
LuaCheckParam( L, 8, dB_Start) ;
|
|
LuaCheckParam( L, 9, dC_Start) ;
|
|
double dX_End = 0. ; double dY_End = 0. ; double dZ_End = 0. ;
|
|
double dA_End = 0. ; double dB_End = 0. ; double dC_End = 0. ;
|
|
LuaCheckParam( L, 10, dX_End) ;
|
|
LuaCheckParam( L, 11, dY_End) ;
|
|
LuaCheckParam( L, 12, dZ_End) ;
|
|
LuaCheckParam( L, 13, dA_End) ;
|
|
LuaCheckParam( L, 14, dB_End) ;
|
|
LuaCheckParam( L, 15, dC_End) ;
|
|
LuaClearStack( L) ;
|
|
// Aggiungo la Lavorazione
|
|
bool bOk = ExeOptMachAddMachining( nId, nToolId, nGroup,
|
|
dX_Start, dY_Start, dZ_Start, dA_Start, dB_Start, dC_Start,
|
|
dX_End, dY_End, dZ_End, dA_End, dB_End, dC_End) ;
|
|
// Rstituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaOptMachSetFirstMachining( lua_State* L)
|
|
{
|
|
// 1 parametro : nId
|
|
int nId = 0 ;
|
|
LuaCheckParam( L, 1, nId) ;
|
|
LuaClearStack( L) ;
|
|
// Imposto la prima lavorazione
|
|
bool bOk = ExeOptMachSetFirstMachining( nId) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
static int
|
|
LuaOptMachSetLastMachining( lua_State* L)
|
|
{
|
|
// 1 parametro : nId
|
|
int nId = 0 ;
|
|
LuaCheckParam( L, 1, nId) ;
|
|
LuaClearStack( L) ;
|
|
// Imposto la prima lavorazione
|
|
bool bOk = ExeOptMachSetLastMachining( nId) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
static int
|
|
LuaOptMachSetFeeds( lua_State* L)
|
|
{
|
|
// 2 Parametri : dFeedL, dFeedA
|
|
double dFeedL = 1. ;
|
|
LuaCheckParam( L, 1, dFeedL) ;
|
|
double dFeedA = 1. ;
|
|
LuaCheckParam( L, 2, dFeedA) ;
|
|
LuaClearStack( L) ;
|
|
// Imposto le Feeds
|
|
bool bOk = ExeOptMachSetFeeds( dFeedL, dFeedA) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaOptMachAddDependence( lua_State* L)
|
|
{
|
|
// 2 parametri : nIdPrev, nIdSucc
|
|
int nIdPrev = 0 ; int nIdNext = 0 ;
|
|
LuaCheckParam( L, 1, nIdPrev) ;
|
|
LuaCheckParam( L, 2, nIdNext) ;
|
|
LuaClearStack( L) ;
|
|
// Imposto Dipendenza obbligatoria
|
|
bool bOk = ExeOptMachAddDependence( nIdPrev, nIdNext) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaOptMachAddSuggestedDependence( lua_State* L)
|
|
{
|
|
// 2 parametri : nIdPrev, nIdSucc
|
|
int nIdPrev = 0 ; int nIdNext = 0 ;
|
|
LuaCheckParam( L, 1, nIdPrev) ;
|
|
LuaCheckParam( L, 2, nIdNext) ;
|
|
LuaClearStack( L) ;
|
|
// Imposto Dipendenza suggerita
|
|
bool bOk = ExeOptMachAddSuggestedDependence( nIdPrev, nIdNext) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaOptMachSetAllGroupDependencesAsMandatory( lua_State* L)
|
|
{
|
|
// 1 Parametro : bAllMendatory
|
|
bool bAllMendatory = false ;
|
|
LuaCheckParam( L, 1, bAllMendatory) ;
|
|
LuaClearStack( L) ;
|
|
// Imposto il Flag
|
|
bool bOk = ExeOptMachSetAllGroupDependencesAsMandatory( bAllMendatory) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaOptMachGetResult( lua_State* L)
|
|
{
|
|
// nessun parametro
|
|
LuaClearStack( L) ;
|
|
// eseguo calcolo di minimo percorso
|
|
INTVECTOR vOrder ;
|
|
bool bOk = ExeOptMachGetResult( vOrder) ;
|
|
// restituisco il risultato
|
|
if ( bOk)
|
|
LuaSetParam( L, vOrder) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
bool
|
|
LuaInstallMachiningOptimization( LuaMgr& luaMgr)
|
|
{
|
|
bool bOk = ( &luaMgr != nullptr) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtOptMachInit", LuaOptMachInit) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtOptMachTerminate", LuaOptMachTerminate) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtOptMachAddTool", LuaOptMachAddTool) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtOptMachAddMachining", LuaOptMachAddMachining) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtOptMachSetFirstMachining", LuaOptMachSetFirstMachining) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtOptMachSetLastMachining", LuaOptMachSetLastMachining) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtOptMachSetFeeds", LuaOptMachSetFeeds) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtOptMachAddDependence", LuaOptMachAddDependence) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtOptMachAddSuggestedDependence", LuaOptMachAddSuggestedDependence) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtOptMachSetAllGroupsDependencesAsMandatory", LuaOptMachSetAllGroupDependencesAsMandatory) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtOptMachGetResult", LuaOptMachGetResult) ;
|
|
return bOk ;
|
|
} |