//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : LUA_General.cpp Data : 27.09.14 Versione : 1.5i5 // Contenuto : Funzioni generali per LUA. // // // // Modifiche : 27.09.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" #include "LUA.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkGdbConst.h" #include "/EgtDev/Include/EGkLuaAux.h" #include "/EgtDev/Include/EGnFileUtils.h" using namespace std ; //------------------------------------------------------------------------------- static int LuaCreateContext( lua_State* L) { // nessun parametro LuaClearStack( L) ; // creo il contesto (senza grafica) int nCtx = ExeInitContext() ; // restituisco il risultato if ( nCtx != 0) LuaSetParam( L, nCtx) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSetContext( lua_State* L) { // un solo parametro intero int nGseCtx ; LuaCheckParam( L, 1, nGseCtx) LuaClearStack( L) ; // imposto il contesto bool bOk = ExeSetCurrentContext( nGseCtx) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetContext( lua_State* L) { // nessun parametro LuaClearStack( L) ; // recupero il contesto corrente int nCtx = ExeGetCurrentContext() ; // restituisco il risultato if ( nCtx != 0) LuaSetParam( L, nCtx) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaDeleteContext( lua_State* L) { // un solo parametro intero int nGseCtx ; LuaCheckParam( L, 1, nGseCtx) LuaClearStack( L) ; // posso cancellare solo contesti senza grafica (con lua si possono creare solo così) GseContext* pGseCtx = GetGseContext( nGseCtx) ; bool bOk = false ; if ( pGseCtx != nullptr && pGseCtx->m_pScene == nullptr) bOk = ExeDeleteContext( nGseCtx) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSetDefaultMaterial( lua_State* L) { // un solo parametro, il colore Color colDef ; LuaCheckParam( L, 1, colDef) LuaClearStack( L) ; // imposto il colore di default int vCol[4] ; colDef.GetInt( vCol) ; bool bOk = ExeSetDefaultMaterial( vCol) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSetGridFrame( lua_State* L) { // 1 o nessun parametro : [Frame] Frame3d frFrame ; if ( lua_gettop( L) >= 1) LuaCheckParam( L, 1, frFrame) ; LuaClearStack( L) ; // imposto il riferimento della Griglia (o CPlane) bool bOk = ExeSetGridFrame( frFrame) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetGridFrame( lua_State* L) { // 1 o nessun parametro : [nRefId] int nRefId = GDB_ID_ROOT ; if ( lua_gettop( L) >= 1) LuaCheckParam( L, 1, nRefId) LuaClearStack( L) ; // recupero il riferimento della griglia Frame3d frFrame ; ExeGetGridFrame( nRefId, frFrame) ; // restituisco il risultato LuaSetParam( L, frFrame) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetGridVersZ( lua_State* L) { // 1 o nessun parametro : [nRefId] int nRefId = GDB_ID_ROOT ; if ( lua_gettop( L) >= 1) LuaCheckParam( L, 1, nRefId) LuaClearStack( L) ; // recupero il versore Z della griglia e lo restituisco Vector3d vtVersZ ; if ( ExeGetGridVersZ( nRefId, vtVersZ)) LuaSetParam( L, vtVersZ) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSetCurrFilePath( lua_State* L) { // 1 parametro : sFilePath string sFilePath ; LuaCheckParam( L, 1, sFilePath) LuaClearStack( L) ; // imposto la path del file corrente bool bOk = ExeSetCurrFilePath( sFilePath) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetCurrFilePath( lua_State* L) { // nessun parametro LuaClearStack( L) ; // recupero la path del file corrente string sFilePath ; bool bOk = ExeGetCurrFilePath( sFilePath) ; // restituisco il risultato if ( bOk) LuaSetParam( L, sFilePath) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaEnableModified( lua_State* L) { // nessun parametro LuaClearStack( L) ; // abilito possibilità di alterare il flag di modifica bool bOk = ExeEnableModified() ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaDisableModified( lua_State* L) { // nessun parametro LuaClearStack( L) ; // disabilito possibilità di alterare il flag di modifica bool bOk = ExeDisableModified() ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetEnableModified( lua_State* L) { // nessun parametro LuaClearStack( L) ; // determino la possibilità di alterare il flag di modifica bool bOk = ExeGetEnableModified() ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetModified( lua_State* L) { // nessun parametro LuaClearStack( L) ; // restituisco il flag di modificato bool bOk = ExeGetModified() ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaNewFile( lua_State* L) { // nessun parametro LuaClearStack( L) ; // nuovo progetto bool bOk = ExeNewFile() ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaOpenFile( lua_State* L) { // 1 parametro : path del file da aprire string sFilePath ; LuaCheckParam( L, 1, sFilePath) LuaClearStack( L) ; // apro il file bool bOk = ExeOpenFile( sFilePath) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaInsertFile( lua_State* L) { // 1 parametro : path del file da importare string sFilePath ; LuaCheckParam( L, 1, sFilePath) LuaClearStack( L) ; // apro il file bool bOk = ExeInsertFile( sFilePath) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSaveFile( lua_State* L) { // nessuno o 1 o 2 parametri : [path del file] [, flag] string sFilePath ; ExeGetCurrFilePath( sFilePath) ; int nFlag = GDB_SV_CMPTXT ; if ( LuaGetParam( L, 1, sFilePath)) LuaGetParam( L, 2, nFlag) ; else { int nType = ExeGetFileType( sFilePath) ; if ( nType != FT_NGE && nType != FT_NFE) sFilePath = ChangeFileExtension( sFilePath, "nge") ; LuaGetParam( L, 1, nFlag) ; } LuaClearStack( L) ; // salvo il file bool bOk = ExeSaveFile( sFilePath, nFlag) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSaveObjToFile( lua_State* L) { // 2 o 3 parametri : nId, path del file [, flag] int nId ; LuaCheckParam( L, 1, nId) string sFilePath ; LuaCheckParam( L, 2, sFilePath) int nFlag = GDB_SV_CMPTXT ; LuaGetParam( L, 3, nFlag) ; LuaClearStack( L) ; // copio il gruppo nel file bool bOk = ExeSaveObjToFile( nId, sFilePath, nFlag) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSaveMachGroupToFile( lua_State* L) { // 2 o 3 parametri : nMGroupId, path del file [, flag] int nMGroupId ; LuaCheckParam( L, 1, nMGroupId) string sFilePath ; LuaCheckParam( L, 2, sFilePath) int nFlag = GDB_SV_CMPTXT ; LuaGetParam( L, 3, nFlag) ; LuaClearStack( L) ; // copio il gruppo nel file bool bOk = ExeSaveMachGroupToFile( nMGroupId, sFilePath, nFlag) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- bool LuaInstallGeomDB( LuaMgr& luaMgr) { bool bOk = ( &luaMgr != nullptr) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCreateContext", LuaCreateContext) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSetContext", LuaSetContext) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetContext", LuaGetContext) ; bOk = bOk && luaMgr.RegisterFunction( "EgtDeleteContext", LuaDeleteContext) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSetDefaultMaterial", LuaSetDefaultMaterial) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSetGridFrame", LuaSetGridFrame) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetGridFrame", LuaGetGridFrame) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetGridVersZ", LuaGetGridVersZ) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSetCurrFilePath", LuaSetCurrFilePath) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetCurrFilePath", LuaGetCurrFilePath) ; bOk = bOk && luaMgr.RegisterFunction( "EgtEnableModified", LuaEnableModified) ; bOk = bOk && luaMgr.RegisterFunction( "EgtDisableModified", LuaDisableModified) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetEnableModified", LuaGetEnableModified) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetModified", LuaGetModified) ; bOk = bOk && luaMgr.RegisterFunction( "EgtNewFile", LuaNewFile) ; bOk = bOk && luaMgr.RegisterFunction( "EgtOpenFile", LuaOpenFile) ; bOk = bOk && luaMgr.RegisterFunction( "EgtInsertFile", LuaInsertFile) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSaveFile", LuaSaveFile) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSaveObjToFile", LuaSaveObjToFile) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSaveMachGroupToFile", LuaSaveMachGroupToFile) ; return bOk ; }