From 93feb71bec44a9a479f2c60985bcbc0e34d23a59 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 6 Jun 2016 06:34:18 +0000 Subject: [PATCH] EgtExecutor : - aggiunte a Lua EgtGetLastPart, EgtGetPrevPart, EgtGetLastLayer e EgtGetPrevLayer - aggiunto parametro opzionale (separatore) a EgtSplitString di Lua - corrette (parametro di ritorno di tipo errato) EgtPackBox e EgtPackBoxCluster di Lua. --- LUA_GdbPartLayers.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++ LUA_General.cpp | 7 ++-- LUA_Nesting.cpp | 8 ++--- 3 files changed, 91 insertions(+), 6 deletions(-) diff --git a/LUA_GdbPartLayers.cpp b/LUA_GdbPartLayers.cpp index 327024a..5aab532 100644 --- a/LUA_GdbPartLayers.cpp +++ b/LUA_GdbPartLayers.cpp @@ -159,6 +159,44 @@ LuaGetNextPart( lua_State* L) return 1 ; } +//------------------------------------------------------------------------------- +static int +LuaGetLastPart( lua_State* L) +{ + // nessuno o 1 parametro : [bOnlyVisible] + bool bOnlyVisible = false ; + LuaGetParam( L, 1, bOnlyVisible) ; + LuaClearStack( L) ; + // cerco ultimo pezzo + int nId = ExeGetLastPart( bOnlyVisible) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetPrevPart( lua_State* L) +{ + // 1 o 2 parametri : nPartId [, bOnlyVisible] + int nPartId ; + LuaCheckParam( L, 1, nPartId) + bool bOnlyVisible = false ; + LuaGetParam( L, 2, bOnlyVisible) ; + LuaClearStack( L) ; + // cerco pezzo precedente + int nId = ExeGetPrevPart( nPartId, bOnlyVisible) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + //------------------------------------------------------------------------------- static int LuaGetFirstLayer( lua_State* L) @@ -199,6 +237,46 @@ LuaGetNextLayer( lua_State* L) return 1 ; } +//------------------------------------------------------------------------------- +static int +LuaGetLastLayer( lua_State* L) +{ + // 1 o 2 parametri : nPartId [, bOnlyVisible] + int nPartId ; + LuaCheckParam( L, 1, nPartId) + bool bOnlyVisible = false ; + LuaGetParam( L, 2, bOnlyVisible) ; + LuaClearStack( L) ; + // cerco l'ultimo layer del pezzo + int nId = ExeGetLastLayer( nPartId, bOnlyVisible) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaGetPrevLayer( lua_State* L) +{ + // 1 o 2 parametri : nLayerId [, bOnlyVisible] + int nLayerId ; + LuaCheckParam( L, 1, nLayerId) + bool bOnlyVisible = false ; + LuaGetParam( L, 2, bOnlyVisible) ; + LuaClearStack( L) ; + // cerco il precedente layer (ovviamente dello stesso pezzo) + int nId = ExeGetPrevLayer( nLayerId, bOnlyVisible) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + //------------------------------------------------------------------------------- static int LuaEraseEmptyParts( lua_State* L) @@ -303,8 +381,12 @@ LuaInstallGdbPartLayer( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtGetPartCount", LuaGetPartCount) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstPart", LuaGetFirstPart) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetNextPart", LuaGetNextPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetLastPart", LuaGetLastPart) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetPrevPart", LuaGetPrevPart) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstLayer", LuaGetFirstLayer) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetNextLayer", LuaGetNextLayer) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetLastLayer", LuaGetLastLayer) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetPrevLayer", LuaGetPrevLayer) ; bOk = bOk && luaMgr.RegisterFunction( "EgtEraseEmptyParts", LuaEraseEmptyParts) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSelectPartObjs", LuaSelectPartObjs) ; bOk = bOk && luaMgr.RegisterFunction( "EgtDeselectPartObjs", LuaDeselectPartObjs) ; diff --git a/LUA_General.cpp b/LUA_General.cpp index 5dd837c..80f0a80 100644 --- a/LUA_General.cpp +++ b/LUA_General.cpp @@ -147,14 +147,17 @@ LuaNumToString( lua_State* L) static int LuaSplitString( lua_State* L) { - // 1 parametro : sVal + // 1 o 2 parametri : sVal [, sSep] string sVal ; + string sSep = "," ; bool bFound = LuaGetParam( L, 1, sVal) ; + if ( bFound) + LuaGetParam( L, 2, sSep) ; LuaClearStack( L) ; // se ricevuta stringa, la divido in parti separate da ',' if ( bFound) { STRVECTOR vsVal ; - FromString( sVal, vsVal) ; + Tokenize( sVal, sSep, vsVal) ; // ritorno il risultato LuaSetParam( L, vsVal) ; } diff --git a/LUA_Nesting.cpp b/LUA_Nesting.cpp index 2adc660..75076f1 100644 --- a/LUA_Nesting.cpp +++ b/LUA_Nesting.cpp @@ -39,9 +39,9 @@ LuaPackBox( lua_State* L) LuaCheckParam( L, 7, bBottomUp) LuaClearStack( L) ; // eseguo il nesting del pezzo - int nTot = ExePackBox( nId, dXmin, dYmin, dXmax, dYmax, dOffs, bBottomUp) ; + bool bOk = ExePackBox( nId, dXmin, dYmin, dXmax, dYmax, dOffs, bBottomUp) ; // restituisco il risultato - LuaSetParam( L, nTot) ; + LuaSetParam( L, bOk) ; return 1 ; } @@ -66,9 +66,9 @@ LuaPackBoxCluster( lua_State* L) LuaCheckParam( L, 7, bBottomUp) LuaClearStack( L) ; // eseguo il nesting dell'insieme di pezzi - int nTot = ExePackBoxCluster( vIds, dXmin, dYmin, dXmax, dYmax, dOffs, bBottomUp) ; + bool bOk = ExePackBoxCluster( vIds, dXmin, dYmin, dXmax, dYmax, dOffs, bBottomUp) ; // restituisco il risultato - LuaSetParam( L, nTot) ; + LuaSetParam( L, bOk) ; return 1 ; }