//---------------------------------------------------------------------------- // EgalTech 2020-2020 //---------------------------------------------------------------------------- // File : LUA_GdbGetVol.cpp Data : 23.03.20 Versione : 2.2c3 // Contenuto : Funzioni di interrogazione dei solidi per LUA. // // // // Modifiche : 23.03.20 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "LUA.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkGdbConst.h" #include "/EgtDev/Include/EGkLuaAux.h" //---------------------------------------------------------------------------- static int LuaVolZmapVolume( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il suo volume double dVol ; if ( ExeVolZmapVolume( nId, dVol)) LuaSetParam( L, dVol) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaVolZmapResolution( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero la risoluzione grafica del solido Zmap int nRes = ExeVolZmapResolution( nId) ; if ( nRes > 0) LuaSetParam( L, nRes) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaVolZmapPartCount( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il numero di parti del solido Zmap int nParts = ExeVolZmapPartCount( nId) ; if ( nParts >= 0) LuaSetParam( L, nParts) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaVolZmapPartVolume( lua_State* L) { // 2 parametri : Id, nPartInd (0-based) int nId ; LuaCheckParam( L, 1, nId) int nPartInd ; LuaCheckParam( L, 2, nPartInd) LuaClearStack( L) ; // recupero il suo eventuale volume double dVol ; if ( ExeVolZmapPartVolume( nId, nPartInd, dVol)) LuaSetParam( L, dVol) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaVolZmapGetPartBBox( lua_State* L) { // 3 parametri : nId, nPart, nFlag int nId ; LuaCheckParam( L, 1, nId) int nPart ; LuaCheckParam( L, 2, nPart) int nFlag ; LuaCheckParam( L, 3, nFlag) LuaClearStack( L) ; // recupero il bounding box della parte in locale BBox3d b3Box ; bool bOk = ExeVolZmapGetPartBBox( nId, nPart, nFlag, b3Box) ; // restituisco il risultato if ( bOk) LuaSetParam( L, b3Box) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaVolZmapGetPartBBoxGlob( lua_State* L) { // 3 parametri : nId, nPart, nFlag int nId ; LuaCheckParam( L, 1, nId) int nPart ; LuaCheckParam( L, 2, nPart) int nFlag ; LuaCheckParam( L, 3, nFlag) LuaClearStack( L) ; // recupero il bounding box della parte in globale BBox3d b3Box ; bool bOk = ExeVolZmapGetPartBBoxGlob( nId, nPart, nFlag, b3Box) ; // restituisco il risultato if ( bOk) LuaSetParam( L, b3Box) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaVolZmapGetPartMinDist( lua_State* L) { // 2 o 3 parametri : nId, ptNear [, nRefType] int nId ; LuaCheckParam( L, 1, nId) Point3d ptNear ; LuaCheckParam( L, 2, ptNear) int nRefType = RTY_DEFAULT ; LuaGetParam( L, 3, nRefType) ; LuaClearStack( L) ; // ricerca int nPart ; bool bOk = ExeVolZmapGetPartMinDist( nId, ptNear, nRefType, nPart) ; if ( bOk) LuaSetParam( L, nPart) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCopyVolZmapPart( lua_State* L) { // 3 parametri : Id, nPart(0-based), nDestGrpId int nId ; LuaCheckParam( L, 1, nId) int nPart ; LuaCheckParam( L, 2, nPart) int nDestGrpId ; LuaCheckParam( L, 3, nDestGrpId) LuaClearStack( L) ; // copio la parte indicata nel gruppo specificato int nNewId = ExeCopyVolZmapPart( nId, nPart, nDestGrpId) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaVolZmapGetDepth( lua_State* L) { // 3 o 4 o 5 parametri : nId, ptP, vtDir [, nRefType] [, bExact] int nId ; LuaCheckParam( L, 1, nId) Point3d ptP ; LuaCheckParam( L, 2, ptP) Vector3d vtDir ; LuaCheckParam( L, 3, vtDir) int nRefType = RTY_DEFAULT ; bool bExact = false ; if ( LuaGetParam( L, 4, nRefType)) LuaGetParam( L, 5, bExact) ; else LuaGetParam( L, 4, bExact) ; LuaClearStack( L) ; // eseguo calcolo profondità dal punto lungo la direzione double dLen1, dLen2 ; bool bOk = ExeVolZmapGetDepth( nId, ptP, vtDir, nRefType, bExact, dLen1, dLen2) ; // restituisco il risultato if ( bOk) { LuaSetParam( L, dLen1) ; LuaSetParam( L, dLen2) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; } return 2 ; } //---------------------------------------------------------------------------- static int LuaVolZmapGetEdges( lua_State* L) { // 2 parametri : nId, nDestGrpId int nId ; LuaCheckParam( L, 1, nId) int nDestGrpId ; LuaCheckParam( L, 2, nDestGrpId) LuaClearStack( L) ; // calcolo gli spigoli del solido int nCount ; int nFirstId = ExeVolZmapGetEdges( nId, nDestGrpId, &nCount) ; // restituisco il risultato if ( nFirstId != GDB_ID_NULL) { LuaSetParam( L, nFirstId) ; LuaSetParam( L, nCount) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; } return 2 ; } //------------------------------------------------------------------------------- bool LuaInstallGdbGetVol( LuaMgr& luaMgr) { bool bOk = ( &luaMgr != nullptr) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapVolume", LuaVolZmapVolume) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapResolution", LuaVolZmapResolution) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapPartCount", LuaVolZmapPartCount) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapPartVolume", LuaVolZmapPartVolume) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapGetPartBBox", LuaVolZmapGetPartBBox) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapGetPartBBoxGlob", LuaVolZmapGetPartBBoxGlob) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapGetPartMinDist", LuaVolZmapGetPartMinDist) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCopyVolZmapPart", LuaCopyVolZmapPart) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapGetDepth", LuaVolZmapGetDepth) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapGetEdges", LuaVolZmapGetEdges) ; return bOk ; }