//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : LUA_GdbObjects.cpp Data : 30.09.14 Versione : 1.5i5 // Contenuto : Funzioni di iterazione di DB geometrico per LUA. // // // // Modifiche : 30.09.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "LUA.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EGkGdbConst.h" #include "/EgtDev/Include/EGkLuaAux.h" using namespace std ; //------------------------------------------------------------------------------- static int LuaExistsObj( lua_State* L) { // 1 parametro : Id int nId = GDB_ID_NULL ; LuaGetParam( L, 1, nId) ; LuaClearStack( L) ; // verifico esistenza oggetto bool bOk = ExeExistsObj( nId) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetParent( lua_State* L) { // 1 parametro : Id int nId = GDB_ID_NULL ; LuaGetParam( L, 1, nId) ; LuaClearStack( L) ; // cerco il padre dell'oggetto indicato int nParentId = ExeGetParent( nId) ; // restituisco il risultato if ( nParentId != GDB_ID_NULL) LuaSetParam( L, nParentId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetType( lua_State* L) { // 1 parametro : Id int nId = GDB_ID_NULL ; LuaGetParam( L, 1, nId) ; LuaClearStack( L) ; // recupero tipo dell'oggetto int nType = ExeGetType( nId) ; // restituisco il risultato LuaSetParam( L, nType) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetGlobFrame( lua_State* L) { // 1 parametro : Id int nId = GDB_ID_NULL ; LuaGetParam( L, 1, nId) ; LuaClearStack( L) ; // recupero il frame Frame3d frFrame ; if ( ExeGetGlobFrame( nId, frFrame)) LuaSetParam( L, frFrame) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetGroupGlobFrame( lua_State* L) { // 1 parametro : Id int nId = GDB_ID_NULL ; LuaGetParam( L, 1, nId) ; LuaClearStack( L) ; // recupero il frame Frame3d frFrame ; if ( ExeGetGroupGlobFrame( nId, frFrame)) LuaSetParam( L, frFrame) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetGroupObjs( lua_State* L) { // 1 parametro : GroupId int nGroupId ; LuaCheckParam( L, 1, nGroupId) LuaClearStack( L) ; // determino il numero di oggetti nel gruppo int nObjs = ExeGetGroupObjs( nGroupId) ; // restituisco il risultato LuaSetParam( L, nObjs) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetAllInGroup( lua_State* L) { // 1 parametro : GroupId int nGroupId ; LuaCheckParam( L, 1, nGroupId) LuaClearStack( L) ; // determino gli oggetti nel gruppo INTVECTOR vIds ; bool bOk = ExeGetAllInGroup( nGroupId, vIds) ; // restituisco il risultato if ( bOk) LuaSetParam( L, vIds) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetFirstInGroup( lua_State* L) { // 1 parametro : GroupId int nGroupId = GDB_ID_NULL ; LuaGetParam( L, 1, nGroupId) ; LuaClearStack( L) ; // recupero il primo oggetto del gruppo int nId = ExeGetFirstInGroup( nGroupId) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetParam( L, nId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetNext( lua_State* L) { // 1 parametro : Id int nId = GDB_ID_NULL ; LuaGetParam( L, 1, nId) ; LuaClearStack( L) ; // recupero il prossimo oggetto nello stesso gruppo int nNextId = ExeGetNext( nId) ; // restituisco il risultato if ( nNextId != GDB_ID_NULL) LuaSetParam( L, nNextId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetLastInGroup( lua_State* L) { // 1 parametro : GroupId int nGroupId = GDB_ID_NULL ; LuaGetParam( L, 1, nGroupId) ; LuaClearStack( L) ; // recupero l'ultimo oggetto del gruppo int nId = ExeGetLastInGroup( nGroupId) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetParam( L, nId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetPrev( lua_State* L) { // 1 parametro : Id int nId = GDB_ID_NULL ; LuaGetParam( L, 1, nId) ; LuaClearStack( L) ; // recupero il precedente oggetto nello stesso gruppo int nPrevId = ExeGetPrev( nId) ; // restituisco il risultato if ( nPrevId != GDB_ID_NULL) LuaSetParam( L, nPrevId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetFirstNameInGroup( lua_State* L) { // 2 parametri : GroupId, sName int nGroupId = GDB_ID_NULL ; LuaGetParam( L, 1, nGroupId) ; string sName ; LuaGetParam( L, 2, sName) ; LuaClearStack( L) ; // recupero il primo oggetto del gruppo con il nome desiderato int nId = ExeGetFirstNameInGroup( nGroupId, sName) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetParam( L, nId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetNextName( lua_State* L) { // 2 parametri : Id, sName int nId = GDB_ID_NULL ; LuaGetParam( L, 1, nId) ; string sName ; LuaGetParam( L, 2, sName) ; LuaClearStack( L) ; // recupero il prossimo oggetto nello stesso gruppo con il nome desiderato int nNextId = ExeGetNextName( nId, sName) ; // restituisco il risultato if ( nNextId != GDB_ID_NULL) LuaSetParam( L, nNextId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetLastNameInGroup( lua_State* L) { // 2 parametri : GroupId, sName int nGroupId = GDB_ID_NULL ; LuaGetParam( L, 1, nGroupId) ; string sName ; LuaGetParam( L, 2, sName) ; LuaClearStack( L) ; // recupero l'ultimo oggetto del gruppo con il nome desiderato int nId = ExeGetLastNameInGroup( nGroupId, sName) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetParam( L, nId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetPrevName( lua_State* L) { // 2 parametri : Id, sName int nId = GDB_ID_NULL ; LuaGetParam( L, 1, nId) ; string sName ; LuaGetParam( L, 2, sName) ; LuaClearStack( L) ; // recupero il precedente oggetto nello stesso gruppo con il nome desiderato int nPrevId = ExeGetPrevName( nId, sName) ; // restituisco il risultato if ( nPrevId != GDB_ID_NULL) LuaSetParam( L, nPrevId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetNameInGroup( lua_State* L) { // 2 parametri : GroupId, sName int nGroupId = GDB_ID_NULL ; LuaGetParam( L, 1, nGroupId) ; string sName ; LuaGetParam( L, 2, sName) ; LuaClearStack( L) ; // recupero tutti gli oggetti del gruppo con il nome o suo inizio desiderato INTVECTOR vIds ; bool bOk = ExeGetNameInGroup( nGroupId, sName, vIds) ; // restituisco il risultato if ( bOk) LuaSetParam( L, vIds) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetInfoInGroup( lua_State* L) { // 2 parametri : GroupId, sKey int nGroupId = GDB_ID_NULL ; LuaGetParam( L, 1, nGroupId) ; string sKey ; LuaGetParam( L, 2, sKey) ; LuaClearStack( L) ; // recupero tutti gli oggetti con l'info richiesta INTVECTOR vIds ; bool bOk = ExeGetInfoInGroup( nGroupId, sKey, vIds) ; // restituisco il risultato if ( bOk) LuaSetParam( L, vIds) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetFirstGroupInGroup( lua_State* L) { // 1 parametro : GroupId int nGroupId = GDB_ID_NULL ; LuaGetParam( L, 1, nGroupId) ; LuaClearStack( L) ; // recupero il primo oggetto gruppo del gruppo int nId = ExeGetFirstGroupInGroup( nGroupId) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetParam( L, nId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetNextGroup( lua_State* L) { // 1 parametro : Id int nId = GDB_ID_NULL ; LuaGetParam( L, 1, nId) ; LuaClearStack( L) ; // recupero il prossimo oggetto gruppo dello stesso gruppo int nNewId = ExeGetNextGroup( nId) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetLastGroupInGroup( lua_State* L) { // 1 parametro : GroupId int nGroupId = GDB_ID_NULL ; LuaGetParam( L, 1, nGroupId) ; LuaClearStack( L) ; // recupero l'ultimo oggetto gruppo del gruppo int nId = ExeGetLastGroupInGroup( nGroupId) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetParam( L, nId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetPrevGroup( lua_State* L) { // 1 parametro : Id int nId = GDB_ID_NULL ; LuaGetParam( L, 1, nId) ; LuaClearStack( L) ; // recupero il precedenteo oggetto gruppo dello stesso gruppo int nNewId = ExeGetPrevGroup( nId) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetBBox( lua_State* L) { // 2 parametri : Id, nFlag int nId ; LuaCheckParam( L, 1, nId) int nFlag ; LuaCheckParam( L, 2, nFlag) LuaClearStack( L) ; // recupero il bounding box dell'oggetto in locale BBox3d b3Box ; bool bOk = ExeGetBBox( nId, nFlag, b3Box) ; // restituisco il risultato if ( bOk) LuaSetParam( L, b3Box) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetBBoxGlob( lua_State* L) { // 2 parametri : Id, nFlag int nId ; LuaCheckParam( L, 1, nId) int nFlag ; LuaCheckParam( L, 2, nFlag) LuaClearStack( L) ; // recupero il bounding box dell'oggetto in globale BBox3d b3Box ; bool bOk = ExeGetBBoxGlob( nId, nFlag, b3Box) ; // restituisco il risultato if ( bOk) LuaSetParam( L, b3Box) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetBBoxRef( lua_State* L) { // 3 parametri : Id, nFlag, Ref int nId ; LuaCheckParam( L, 1, nId) int nFlag ; LuaCheckParam( L, 2, nFlag) Frame3d frRef ; LuaCheckParam( L, 3, frRef) LuaClearStack( L) ; // recupero il bounding box dell'oggetto in globale BBox3d b3Box ; bool bOk = ExeGetBBoxRef( nId, nFlag, frRef, b3Box) ; // restituisco il risultato if ( bOk) LuaSetParam( L, b3Box) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCopy( lua_State* L) { // 2 o 3 parametri : SouId, RefId [, nSonBeforeAfter] int nSouId ; LuaCheckParam( L, 1, nSouId) int nRefId ; LuaCheckParam( L, 2, nRefId) int nSonBeforeAfter = GDB_LAST_SON ; LuaGetParam( L, 3, nSonBeforeAfter) ; LuaClearStack( L) ; // eseguo la copia int nNewId = ExeCopy( nSouId, nRefId, nSonBeforeAfter) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCopyEx( lua_State* L) { // 4 o 5 parametri : nSouCtx, SouId, nDestCtx, RefId [, nSonBeforeAfter] int nSouCtx ; LuaCheckParam( L, 1, nSouCtx) int nSouId ; LuaCheckParam( L, 2, nSouId) int nDestCtx ; LuaCheckParam( L, 3, nDestCtx) int nRefId ; LuaCheckParam( L, 4, nRefId) int nSonBeforeAfter = GDB_LAST_SON ; LuaGetParam( L, 5, nSonBeforeAfter) ; LuaClearStack( L) ; // eseguo la copia int nNewId = ExeCopyEx( nSouCtx, nSouId, nDestCtx, nRefId, nSonBeforeAfter) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCopyGlob( lua_State* L) { // 2 o 3 parametri : SouId, RefId [, nSonBeforeAfter] int nSouId ; LuaCheckParam( L, 1, nSouId) int nRefId ; LuaCheckParam( L, 2, nRefId) int nSonBeforeAfter = GDB_LAST_SON ; LuaGetParam( L, 3, nSonBeforeAfter) ; LuaClearStack( L) ; // eseguo la copia int nNewId = ExeCopyGlob( nSouId, nRefId, nSonBeforeAfter) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCopyGlobEx( lua_State* L) { // 4 o 5 parametri : nSouCtx, SouId, nDestCtx, RefId [, nSonBeforeAfter] int nSouCtx ; LuaCheckParam( L, 1, nSouCtx) int nSouId ; LuaCheckParam( L, 2, nSouId) int nDestCtx ; LuaCheckParam( L, 3, nDestCtx) int nRefId ; LuaCheckParam( L, 4, nRefId) int nSonBeforeAfter = GDB_LAST_SON ; LuaGetParam( L, 5, nSonBeforeAfter) ; LuaClearStack( L) ; // eseguo la copia int nNewId = ExeCopyGlobEx( nSouCtx, nSouId, nDestCtx, nRefId, nSonBeforeAfter) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaDuplicateGeomDB( lua_State* L) { // 2 o 3 parametri : nSouCtx, nDestCtx [, bSkipTemp] int nSouCtx ; LuaCheckParam( L, 1, nSouCtx) int nDestCtx ; LuaCheckParam( L, 2, nDestCtx) bool bSkipTemp = false ; LuaGetParam( L, 3, bSkipTemp) ; LuaClearStack( L) ; // eseguo la copia bool bOk = ExeDuplicateGeomDB( nSouCtx, nDestCtx, bSkipTemp) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaRelocate( lua_State* L) { // 2 o 3 parametri : SouId, RefId [, nSonBeforeAfter] int nSouId ; LuaCheckParam( L, 1, nSouId) int nRefId ; LuaCheckParam( L, 2, nRefId) int nSonBeforeAfter = GDB_LAST_SON ; LuaGetParam( L, 3, nSonBeforeAfter) ; LuaClearStack( L) ; // eseguo la rilocazione bool bOk = ExeRelocate( nSouId, nRefId, nSonBeforeAfter) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaRelocateGlob( lua_State* L) { // 2 o 3 parametri : SouId, RefId [, SonBeforeAfter] int nSouId ; LuaCheckParam( L, 1, nSouId) int nRefId ; LuaCheckParam( L, 2, nRefId) int nSonBeforeAfter = GDB_LAST_SON ; LuaGetParam( L, 3, nSonBeforeAfter) ; LuaClearStack( L) ; // eseguo la rilocazione bool bOk = ExeRelocateGlob( nSouId, nRefId, nSonBeforeAfter) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGroupSwap( lua_State* L) { // 4 parametri : nId1, nId2, bSwapRef, bMark int nId1 ; LuaCheckParam( L, 1, nId1) int nId2 ; LuaCheckParam( L, 2, nId2) bool bSwapRef ; LuaCheckParam( L, 3, bSwapRef) bool bMark ; LuaCheckParam( L, 4, bMark) LuaClearStack( L) ; // eseguo lo swap tra i gruppi bool bOk = ExeGroupSwap( nId1, nId2, bSwapRef, bMark) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaGetNewId( lua_State* L) { // nessun parametro LuaClearStack( L) ; // richiedo valore nuovo Id int nNewId = ExeGetNewId() ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaChangeId( lua_State* L) { // 2 parametri : Id, nNewId int nId ; LuaCheckParam( L, 1, nId) int nNewId ; LuaCheckParam( L, 2, nNewId) LuaClearStack( L) ; // eseguo il cambio di identificativo bool bOk = ExeChangeId( nId, nNewId) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaErase( lua_State* L) { // 1 parametro : Id/s INTVECTOR vId ; LuaGetParam( L, 1, vId) ; LuaClearStack( L) ; // eseguo la cancellazione bool bOk = ExeErase( vId) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaEmptyGroup( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // eseguo la cancellazione bool bOk = ExeEmptyGroup( nId) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- bool LuaInstallGdbObjects( LuaMgr& luaMgr) { bool bOk = ( &luaMgr != nullptr) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExistsObj", LuaExistsObj) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetParent", LuaGetParent) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetType", LuaGetType) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetGlobFrame", LuaGetGlobFrame) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetGroupGlobFrame", LuaGetGroupGlobFrame) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetGroupObjs", LuaGetGroupObjs) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetAllInGroup", LuaGetAllInGroup) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstInGroup", LuaGetFirstInGroup) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetNext", LuaGetNext) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetLastInGroup", LuaGetLastInGroup) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetPrev", LuaGetPrev) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstNameInGroup", LuaGetFirstNameInGroup) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetNextName", LuaGetNextName) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetLastNameInGroup", LuaGetLastNameInGroup) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetPrevName", LuaGetPrevName) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetNameInGroup", LuaGetNameInGroup) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetInfoInGroup", LuaGetInfoInGroup) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetFirstGroupInGroup", LuaGetFirstGroupInGroup) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetNextGroup", LuaGetNextGroup) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetLastGroupInGroup", LuaGetLastGroupInGroup) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetPrevGroup", LuaGetPrevGroup) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetBBox", LuaGetBBox) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetBBoxGlob", LuaGetBBoxGlob) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetBBoxRef", LuaGetBBoxRef) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCopy", LuaCopy) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCopyEx", LuaCopyEx) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCopyGlob", LuaCopyGlob) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCopyGlobEx", LuaCopyGlobEx) ; bOk = bOk && luaMgr.RegisterFunction( "EgtDuplicateGeomDB", LuaDuplicateGeomDB) ; bOk = bOk && luaMgr.RegisterFunction( "EgtRelocate", LuaRelocate) ; bOk = bOk && luaMgr.RegisterFunction( "EgtRelocateGlob", LuaRelocateGlob) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGroupSwap", LuaGroupSwap) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetNewId", LuaGetNewId) ; bOk = bOk && luaMgr.RegisterFunction( "EgtChangeId", LuaChangeId) ; bOk = bOk && luaMgr.RegisterFunction( "EgtErase", LuaErase) ; bOk = bOk && luaMgr.RegisterFunction( "EgtEmptyGroup", LuaEmptyGroup) ; return bOk ; }