//---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- // File : LUA_Nesting.cpp Data : 08.09.15 Versione : 1.6i5 // Contenuto : Funzioni Nesting per LUA. // // // // Modifiche : 08.09.15 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "LUA.h" #include "/EgtDev/Include/EXeExecutor.h" using namespace std ; //------------------------------------------------------------------------------- static int LuaPackBox( lua_State* L) { // 7 parametri : Id, dXmin, dYmin, dXmax, dYmax, dOffs, bBottomUp int nId ; LuaCheckParam( L, 1, nId) double dXmin ; LuaCheckParam( L, 2, dXmin) double dYmin ; LuaCheckParam( L, 3, dYmin) double dXmax ; LuaCheckParam( L, 4, dXmax) double dYmax ; LuaCheckParam( L, 5, dYmax) double dOffs ; LuaCheckParam( L, 6, dOffs) bool bBottomUp ; LuaCheckParam( L, 7, bBottomUp) LuaClearStack( L) ; // eseguo il nesting del pezzo bool bOk = ExePackBox( nId, dXmin, dYmin, dXmax, dYmax, dOffs, bBottomUp) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaPackBoxCluster( lua_State* L) { // 7 parametri : Id/s, dXmin, dYmin, dXmax, dYmax, dOffs, bBottomUp INTVECTOR vIds ; LuaCheckParam( L, 1, vIds) double dXmin ; LuaCheckParam( L, 2, dXmin) double dYmin ; LuaCheckParam( L, 3, dYmin) double dXmax ; LuaCheckParam( L, 4, dXmax) double dYmax ; LuaCheckParam( L, 5, dYmax) double dOffs ; LuaCheckParam( L, 6, dOffs) bool bBottomUp ; LuaCheckParam( L, 7, bBottomUp) LuaClearStack( L) ; // eseguo il nesting dell'insieme di pezzi bool bOk = ExePackBoxCluster( vIds, dXmin, dYmin, dXmax, dYmax, dOffs, bBottomUp) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaVerifyMachining( lua_State* L) { // 1 parametro : OperId int nOperId ; LuaCheckParam( L, 1, nOperId) LuaClearStack( L) ; // eseguo la verifica di interferenza della lavorazione int nFlag ; bool bOk = ExeVerifyMachining( nOperId, nFlag) ; // restituisco il risultato if ( bOk) LuaSetParam( L, nFlag) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaAutoNestStart( lua_State* L) { // nessu parametro LuaClearStack( L) ; // imposto inizio nuovo nesting bool bOk = ExeAutoNestStart() ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaAutoNestAddSheet( lua_State* L) { // 4 parametri : nSheetId, nOutlineId, nPriority, nCount int nSheetId ; LuaCheckParam( L, 1, nSheetId) int nOutlineId ; LuaCheckParam( L, 2, nOutlineId) int nPriority ; LuaCheckParam( L, 3, nPriority) int nCount ; LuaCheckParam( L, 4, nCount) LuaClearStack( L) ; // aggiungo un pannello al nesting corrente bool bOk = ExeAutoNestAddSheet( nSheetId, nOutlineId, nPriority, nCount) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaAutoNestAddPart( lua_State* L) { // 3 parametri : nPartId, nOutlineId, nCount int nPartId ; LuaCheckParam( L, 1, nPartId) int nOutlineId ; LuaCheckParam( L, 2, nOutlineId) int nCount ; LuaCheckParam( L, 3, nCount) LuaClearStack( L) ; // aggiungo un pezzo al nesting corrente bool bOk = ExeAutoNestAddPart( nPartId, nOutlineId, nCount) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaAutoNestSetInterpartGap( lua_State* L) { // 1 parametro : dGap double dGap ; LuaCheckParam( L, 1, dGap) LuaClearStack( L) ; // imposto la distanza minima tra i pezzi al nesting corrente bool bOk = ExeAutoNestSetInterpartGap( dGap) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaAutoNestCompute( lua_State* L) { // 1 parametro : nMaxTime (ms) int nMaxTime ; LuaCheckParam( L, 1, nMaxTime) LuaClearStack( L) ; // lancio calcolo del nesting bool bOk = ExeAutoNestCompute( nMaxTime) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaAutoNestGetComputationStatus( lua_State* L) { // nessun parametro LuaClearStack( L) ; // lancio calcolo del nesting int nStatus ; bool bOk = ExeAutoNestGetComputationStatus( nStatus) ; // restituisco il risultato LuaSetParam( L, bOk) ; LuaSetParam( L, nStatus) ; return 2 ; } //------------------------------------------------------------------------------- static int LuaAutoNestPrintResults( lua_State* L) { // 1 parametro : sHtmlFile string sHtmlFile ; LuaCheckParam( L, 1, sHtmlFile) LuaClearStack( L) ; // lancio stampa soluzione corrente bool bOk = ExeAutoNestPrintResults( sHtmlFile) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaAutoNestGetResults( lua_State* L) { // nessun parametro LuaClearStack( L) ; // recupero il risultato della soluzione int nNestedParts, nTotParts, nTotSheets, nDiffSheets ; double dTotFillRatio ; bool bOk = ExeAutoNestGetResults( nNestedParts, nTotParts, nTotSheets, nDiffSheets, dTotFillRatio) ; // restituisco il risultato if ( bOk) { LuaSetParam( L, nNestedParts) ; LuaSetParam( L, nTotParts) ; LuaSetParam( L, nTotSheets) ; LuaSetParam( L, nDiffSheets) ; LuaSetParam( L, dTotFillRatio) ; return 5 ; } else { LuaSetParam( L) ; return 1 ; } } //------------------------------------------------------------------------------- static int LuaAutoNestGetOneResult( lua_State* L) { // 1 parametro : nInd int nInd ; LuaCheckParam( L, 1, nInd) LuaClearStack( L) ; // recupero i risultati del nesting int nType, nId, nFlag ; double dX, dY, dAngRot ; bool bOk = ExeAutoNestGetOneResult( nInd, nType, nId, nFlag, dX, dY, dAngRot) ; // restituisco il risultato if ( bOk) { LuaSetParam( L, nType) ; LuaSetParam( L, nId) ; LuaSetParam( L, nFlag) ; LuaSetParam( L, dX) ; LuaSetParam( L, dY) ; LuaSetParam( L, dAngRot) ; return 6 ; } else { LuaSetParam( L) ; return 1 ; } } //------------------------------------------------------------------------------- bool LuaInstallNesting( LuaMgr& luaMgr) { bool bOk = ( &luaMgr != nullptr) ; bOk = bOk && luaMgr.RegisterFunction( "EgtPackBox", LuaPackBox) ; bOk = bOk && luaMgr.RegisterFunction( "EgtPackBoxCluster", LuaPackBoxCluster) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVerifyMachining", LuaVerifyMachining) ; bOk = bOk && luaMgr.RegisterFunction( "EgtAutoNestStart", LuaAutoNestStart) ; bOk = bOk && luaMgr.RegisterFunction( "EgtAutoNestAddSheet", LuaAutoNestAddSheet) ; bOk = bOk && luaMgr.RegisterFunction( "EgtAutoNestAddPart", LuaAutoNestAddPart) ; bOk = bOk && luaMgr.RegisterFunction( "EgtAutoNestSetInterpartGap", LuaAutoNestSetInterpartGap) ; bOk = bOk && luaMgr.RegisterFunction( "EgtAutoNestCompute", LuaAutoNestCompute) ; bOk = bOk && luaMgr.RegisterFunction( "EgtAutoNestGetComputationStatus", LuaAutoNestGetComputationStatus) ; bOk = bOk && luaMgr.RegisterFunction( "EgtAutoNestPrintResults", LuaAutoNestPrintResults) ; bOk = bOk && luaMgr.RegisterFunction( "EgtAutoNestGetResults", LuaAutoNestGetResults) ; bOk = bOk && luaMgr.RegisterFunction( "EgtAutoNestGetOneResult", LuaAutoNestGetOneResult) ; return bOk ; }