Files
EgtExecutor/LUA_MaxFiller.cpp
Dario Sassi c207175e7b EgtExecutor 2.2k1 :
- aggiunte funzioni Exe e Lua per nesting 1D ( MaxFillerStart, MaxFillerAddPart, MaxFillerCompute, MaxFillerGetResults, MaxFillerGetOneResult).
2020-11-06 12:13:52 +00:00

136 lines
4.1 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2020-2020
//----------------------------------------------------------------------------
// File : LUA_MaxFiller.cpp Data : 06.11.20 Versione : 2.2k1
// Contenuto : Funzioni Maximum Filler per LUA.
//
//
//
// Modifiche : 06.11.20 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "LUA.h"
#include "/EgtDev/Include/EXeExecutor.h"
using namespace std ;
//-------------------------------------------------------------------------------
static int
LuaMaxFillerStart( lua_State* L)
{
// nessu parametro
LuaClearStack( L) ;
// imposto inizio riempimento massimo
bool bOk = ExeMaxFillerStart() ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaMaxFillerAddPart( lua_State* L)
{
// 2 o 4 parametri : nPartId, dLen [, dDispLen, nCount]
int nPartId ;
LuaCheckParam( L, 1, nPartId)
double dLen ;
LuaCheckParam( L, 2, dLen)
double dDispLen = dLen ;
LuaGetParam( L, 3, dDispLen) ;
int nCount = 1 ;
LuaGetParam( L, 4, nCount) ;
LuaClearStack( L) ;
// aggiungo un pezzo al nesting corrente
bool bOk = ExeMaxFillerAddPart( nPartId, dLen, dDispLen, nCount) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaMaxFillerCompute( lua_State* L)
{
// 4 o 5 parametri : dLenToFill, dStartGap, dMidGap, dEndGap [, nSortType]
double dLenToFill ;
LuaCheckParam( L, 1, dLenToFill)
double dStartGap ;
LuaCheckParam( L, 2, dStartGap)
double dMidGap ;
LuaCheckParam( L, 3, dMidGap)
double dEndGap ;
LuaCheckParam( L, 4, dEndGap)
int nSortType = 0 ;
LuaGetParam( L, 5, nSortType) ;
LuaClearStack( L) ;
// lancio calcolo del nesting
bool bOk = ExeMaxFillerCompute( dLenToFill, dStartGap, dMidGap, dEndGap, nSortType) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaMaxFillerGetResults( lua_State* L)
{
// nessun parametro
LuaClearStack( L) ;
// recupero il risultato della soluzione
int nFilledParts, nDiffParts ; double dTotFillRatio ;
bool bOk = ExeMaxFillerGetResults( nFilledParts, nDiffParts, dTotFillRatio) ;
// restituisco il risultato
if ( bOk) {
LuaSetParam( L, nFilledParts) ;
LuaSetParam( L, nDiffParts) ;
LuaSetParam( L, dTotFillRatio) ;
return 3 ;
}
else {
LuaSetParam( L) ;
return 1 ;
}
}
//-------------------------------------------------------------------------------
static int
LuaMaxFillerGetOneResult( lua_State* L)
{
// 1 parametro : nInd
int nInd ;
LuaCheckParam( L, 1, nInd)
LuaClearStack( L) ;
// recupero i risultati del nesting
int nPartId, nCount ;
bool bOk = ExeMaxFillerGetOneResult( nInd, nPartId, nCount) ;
// restituisco il risultato
if ( bOk) {
LuaSetParam( L, nPartId) ;
LuaSetParam( L, nCount) ;
return 2 ;
}
else {
LuaSetParam( L) ;
return 1 ;
}
}
//-------------------------------------------------------------------------------
bool
LuaInstallMaxFiller( LuaMgr& luaMgr)
{
bool bOk = ( &luaMgr != nullptr) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtMaxFillerStart", LuaMaxFillerStart) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtMaxFillerAddPart", LuaMaxFillerAddPart) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtMaxFillerCompute", LuaMaxFillerCompute) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtMaxFillerGetResults", LuaMaxFillerGetResults) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtMaxFillerGetOneResult", LuaMaxFillerGetOneResult) ;
return bOk ;
}