diff --git a/EXE_MachOpt.cpp b/EXE_MachOpt.cpp new file mode 100644 index 0000000..d893287 --- /dev/null +++ b/EXE_MachOpt.cpp @@ -0,0 +1,158 @@ +//---------------------------------------------------------------------------- +// EgalTech 2025-2025 +//---------------------------------------------------------------------------- +// File : EXE_MachOpt.cpp Data : 02.04.2025 Versione : 2.7c1 +// Contenuto : Funzioni per Ottimizzare i tempi tra le lavorazioni. +// +// +// +// Modifiche : 02.04.25 RE Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "EXE_Const.h" +#include "DllNesting.h" +#include "/EgtDev/Include/EgtPointerOwner.h" +#include "/EgtDev/Include/ENkMachOptimization.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +// Static LuaMgr per EgtExecutor +//---------------------------------------------------------------------------- +static PtrOwner s_pMO ; + +//---------------------------------------------------------------------------- +bool +ExeOptMachInit( void) +{ + // Creo l'oggetto per il calcolo del percorso minimo (ShortestPath) + s_pMO.Set( CreateMachOptimization()) ; + return ( ! IsNull( s_pMO)) ; +} + +//---------------------------------------------------------------------------- +bool +ExeOptMachTerminate( void) +{ + // Distruggo l'oggetto + s_pMO.Reset() ; + return ( IsNull( s_pMO)) ; +} + +//---------------------------------------------------------------------------- +bool +ExeOptMachAddTool( int nId, double dTCX, double dTCY, double dTCZ, double dTCA, + double dTCB, double dTCC, bool bX, bool bY, bool bZ, bool bA, + bool bB, bool bC, double dTLoad, double dTUnL) +{ + // Se oggetto non instanziato, errore + if ( IsNull( s_pMO)) + return false ; + // Inserisco il Record + return ( s_pMO->InsertTool( nId, dTCX, dTCY, dTCZ, dTCA, dTCB, dTCC, bX, bY, bZ, bA, + bB, bC, dTLoad, dTUnL)) ; +} + +//---------------------------------------------------------------------------- +bool +ExeOptMachAddMachining( int nId, int nToolId, int nGroup, + double dX_Start, double dY_Start, double dZ_Start, + double dA_Start, double dB_Start, double dC_Start, + double dX_End, double dY_End, double dZ_End, + double dA_End, double dB_End, double dC_End) +{ + // Se oggetto non instanziato, errore + if ( IsNull( s_pMO)) + return false ; + // Inserisco il Record + return ( s_pMO->InsertMachining( 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)) ; +} + +//---------------------------------------------------------------------------- +bool +ExeOptMachSetFirstMachining( int nId) +{ + // Se oggetto non instanziato, errore + if ( IsNull( s_pMO)) + return false ; + // Imposto la prima lavorazione + return ( s_pMO->SetFirstMachining( nId)) ; +} + + +//---------------------------------------------------------------------------- +bool +ExeOptMachSetLastMachining( int nId) +{ + // Se oggetto non instanziato, errore + if ( IsNull( s_pMO)) + return false ; + // Imposto l'ultima lavorazione + return ( s_pMO->SetLastMachining( nId)) ; +} + +//---------------------------------------------------------------------------- +bool +ExeOptMachSetFeeds( double dFeedL, double dFeedA) +{ + // Se oggetto non instanziato, errore + if ( IsNull( s_pMO)) + return false ; + // Imposto l'ultima lavorazione + return ( s_pMO->SetFeeds( dFeedL, dFeedA)) ; +} + +//---------------------------------------------------------------------------- +bool +ExeOptMachAddDependence( int nIdPrec, int nIdSucc) +{ + // Se oggetto non instanziato, errore + if ( IsNull( s_pMO)) + return false ; + // Inserisco la Dipendenza obbligatoria + return ( s_pMO->InsertDependence( nIdPrec, nIdSucc)) ; +} + +//---------------------------------------------------------------------------- +bool +ExeOptMachAddSuggestedDependence( int nIdPrec, int nIdSucc) +{ + // Se oggetto non instanziato, errore + if ( IsNull( s_pMO)) + return false ; + // Inserisco la Dipendenza obbligatoria + return ( s_pMO->InsertSuggestedDependences( nIdPrec, nIdSucc)) ; +} + +//---------------------------------------------------------------------------- +bool +ExeOptMachSetAllGroupDependencesAsMandatory( bool bAllMandatory) +{ + // Se oggetto non instanziato, errore + if ( IsNull( s_pMO)) + return false ; + // Imposto il Flag + return ( s_pMO->SetAllGroupsAsMandatory( bAllMandatory)) ; +} + +//---------------------------------------------------------------------------- +bool +ExeOptMachGetResult( INTVECTOR& vIds) +{ + vIds.clear() ; + // Se oggetto non instanziato, errore + if ( IsNull( s_pMO)) + return false ; + // Recupero i risultati + return ( s_pMO->GetResult( vIds)) ; +} \ No newline at end of file diff --git a/EgtExecutor.vcxproj b/EgtExecutor.vcxproj index 597afba..f0cdeb0 100644 --- a/EgtExecutor.vcxproj +++ b/EgtExecutor.vcxproj @@ -264,6 +264,7 @@ copy $(TargetPath) \EgtProg\Dll64 + @@ -314,6 +315,7 @@ copy $(TargetPath) \EgtProg\Dll64 + diff --git a/EgtExecutor.vcxproj.filters b/EgtExecutor.vcxproj.filters index f467eb3..b13b8a7 100644 --- a/EgtExecutor.vcxproj.filters +++ b/EgtExecutor.vcxproj.filters @@ -407,6 +407,12 @@ File di origine\LUA + + File di origine\EXE + + + File di origine\LUA + diff --git a/LUA.h b/LUA.h index a96f600..1e70783 100644 --- a/LUA.h +++ b/LUA.h @@ -1,5 +1,5 @@ //---------------------------------------------------------------------------- -// EgalTech 2014-2024 +// EgalTech 2014-2025 //---------------------------------------------------------------------------- // File : LUA.h Data : 24.03.24 Versione : 2.6c2 // Contenuto : Dichiarazioni locali per moduli LUA. @@ -129,6 +129,9 @@ bool LuaInstallPolynomialRoots( LuaMgr& luaMgr) ; //-------------------------- Shortest Path ----------------------------------- bool LuaInstallShortestPath( LuaMgr& luaMgr) ; +//----------------------- Machining Time Optimization ------------------------ +bool LuaInstallMachiningOptimization( LuaMgr& luaMgr) ; + //-------------------------- Collision Avoidance Tool ------------------------ bool LuaInstallCAvTool( LuaMgr& luaMgr) ; diff --git a/LUA_Base.cpp b/LUA_Base.cpp index 53472f2..4e03115 100644 --- a/LUA_Base.cpp +++ b/LUA_Base.cpp @@ -178,6 +178,10 @@ LuaInstallEgtFunctions( LuaMgr& LuaMgr) LOG_ERROR( GetLogger(), "Error in LuaInstallShortestPath (LuaInstallEgtFunctions)") return false ; } + if ( ! LuaInstallMachiningOptimization( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallMachiningOptimization (LuaInstallEgtFunctions)") + return false ; + } if ( ! LuaInstallCAvTool( LuaMgr)) { LOG_ERROR( GetLogger(), "Error in LuaInstallCAvTool (LuaInstallEgtFunctions)") return false ; diff --git a/LUA_MachOpt.cpp b/LUA_MachOpt.cpp new file mode 100644 index 0000000..ce6bdf9 --- /dev/null +++ b/LUA_MachOpt.cpp @@ -0,0 +1,247 @@ +//---------------------------------------------------------------------------- +// 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 ; +} \ No newline at end of file diff --git a/LUA_ShortestPath.cpp b/LUA_ShortestPath.cpp index 095952b..fbdd49b 100644 --- a/LUA_ShortestPath.cpp +++ b/LUA_ShortestPath.cpp @@ -160,7 +160,7 @@ LuaSpSetZzOwStep( lua_State* L) LuaCheckParam( L, 1, dStep) LuaClearStack( L) ; // imposto lo step per tipologie ZigZag e OneWay - bool bOk = ExeSpSetZzOwStep( dStep) ; + bool bOk = ExeSpSetZzOwStep( dStep) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ;