//---------------------------------------------------------------------------- // EgalTech 2016-2017 //---------------------------------------------------------------------------- // File : LUA_GdbModifyVol.cpp Data : 09.03.17 Versione : 1.8c4 // Contenuto : Funzioni di modifica dei solidi per LUA. // // // // Modifiche : 27.10.16 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "LUA.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkLuaAux.h" using namespace std ; //------------------------------------------------------------------------------- static int LuaExplodeVolume( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // esplosione del solido int nCount ; int nFirstId = ExeExplodeVolume( nId, &nCount) ; if ( nFirstId != GDB_ID_NULL) LuaSetParam( L, nFirstId) ; else LuaSetParam( L) ; LuaSetParam( L, nCount) ; return 2 ; } //---------------------------------------------------------------------------- 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 LuaRemoveVolZmapPart( lua_State* L) { // 2 parametri : Id, nPart(0-based) int nId ; LuaCheckParam( L, 1, nId) int nPart ; LuaCheckParam( L, 2, nPart) LuaClearStack( L) ; // rimuovo la parte indicata bool bOk = ExeRemoveVolZmapPart( nId, nPart) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaVolZmapSetStdTool( lua_State* L) { // 5 o 6 parametri : Id, sToolName, dLen, dDiam, dCornR, nFlag int nId ; LuaCheckParam( L, 1, nId) string sToolName ; LuaCheckParam( L, 2, sToolName) double dLen ; LuaCheckParam( L, 3, dLen) double dDiam ; LuaCheckParam( L, 4, dDiam) double dCornR ; LuaCheckParam( L, 5, dCornR) int nFlag = 1 ; LuaGetParam( L, 6, nFlag) ; LuaClearStack( L) ; // imposto utensile standard a Zmap indicato bool bOk = ExeVolZmapSetStdTool( nId, sToolName, dLen, dDiam, dCornR, nFlag) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaVolZmapSetAdvTool( lua_State* L) { // 7 o 8 parametri : Id, sToolName, dLen, dDiam, dTipLen, dTipDiam, dCornR, nFlag int nId ; LuaCheckParam( L, 1, nId) string sToolName ; LuaCheckParam( L, 2, sToolName) double dLen ; LuaCheckParam( L, 3, dLen) double dDiam ; LuaCheckParam( L, 4, dDiam) double dTipLen ; LuaCheckParam( L, 5, dTipLen) double dTipDiam ; LuaCheckParam( L, 6, dTipDiam) double dCornR ; LuaCheckParam( L, 7, dCornR) int nFlag = 1 ; LuaGetParam( L, 8, nFlag) ; LuaClearStack( L) ; // imposto utensile standard a Zmap indicato bool bOk = ExeVolZmapSetAdvTool( nId, sToolName, dLen, dDiam, dTipLen, dTipDiam, dCornR, nFlag) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaVolZmapSetMortiserTool( lua_State* L) { // 6 o 7 parametri : Id, sToolName, dLen, dWidth, dThick, dCornR, nFlag int nId ; LuaCheckParam( L, 1, nId) string sToolName ; LuaCheckParam( L, 2, sToolName) double dLen ; LuaCheckParam( L, 3, dLen) double dWidth ; LuaCheckParam( L, 4, dWidth) double dThick ; LuaCheckParam( L, 5, dThick) double dCornR ; LuaCheckParam( L, 6, dCornR) int nFlag = 1 ; LuaGetParam( L, 7, nFlag) ; LuaClearStack( L) ; // imposto mortasatrice a Zmap indicato bool bOk = ExeVolZmapSetMortiserTool( nId, sToolName, dLen, dWidth, dThick, dCornR, nFlag) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaVolZmapSetChiselTool( lua_State* L) { // 5 o 6 parametri : Id, sToolName, dLen, dWidth, dThick, nFlag int nId ; LuaCheckParam( L, 1, nId) string sToolName ; LuaCheckParam( L, 2, sToolName) double dLen ; LuaCheckParam( L, 3, dLen) double dWidth ; LuaCheckParam( L, 4, dWidth) double dThick ; LuaCheckParam( L, 5, dThick) int nFlag = 1 ; LuaGetParam( L, 6, nFlag) ; LuaClearStack( L) ; // imposto scalpello a Zmap indicato bool bOk = ExeVolZmapSetChiselTool( nId, sToolName, dLen, dWidth, dThick, nFlag) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaVolZmapMillingStep( lua_State* L) { // 5 o 6 o 7 o 8 parametri : nId, ptPs, vtDs [, vtAs], ptPe, vtDe [, vtAe], [, nRefType] int n = lua_gettop( L) ; if ( n == 5 || n == 6) { int nId ; LuaCheckParam( L, 1, nId) Point3d ptPs ; LuaCheckParam( L, 2, ptPs) Vector3d vtDs ; LuaCheckParam( L, 3, vtDs) Point3d ptPe ; LuaCheckParam( L, 4, ptPe) Vector3d vtDe ; LuaCheckParam( L, 5, vtDe) int nRefType = RTY_DEFAULT ; LuaGetParam( L, 6, nRefType) ; LuaClearStack( L) ; // eseguo movimento di fresatura con l'utensile già associato a Zmap bool bOk = ExeVolZmapMillingStep( nId, ptPs, vtDs, ptPe, vtDe, nRefType) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } else { int nId ; LuaCheckParam( L, 1, nId) Point3d ptPs ; LuaCheckParam( L, 2, ptPs) Vector3d vtDs ; LuaCheckParam( L, 3, vtDs) Vector3d vtAs ; LuaCheckParam( L, 4, vtAs) Point3d ptPe ; LuaCheckParam( L, 5, ptPe) Vector3d vtDe ; LuaCheckParam( L, 6, vtDe) Vector3d vtAe ; LuaCheckParam( L, 7, vtAe) int nRefType = RTY_DEFAULT ; LuaGetParam( L, 8, nRefType) ; LuaClearStack( L) ; // eseguo movimento di fresatura con l'utensile già associato a Zmap bool bOk = ExeVolZmapMillingStep( nId, ptPs, vtDs, vtAs, ptPe, vtDe, vtAe, nRefType) ; // restituisco il risultato LuaSetParam( L, bOk) ; 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 LuaVolZmapIntersPlane( lua_State* L) { // 4 o 5 parametri : nId, ptP, vtN, nDestGrpId [, nRefType] int nId ; LuaCheckParam( L, 1, nId) Point3d ptP ; LuaCheckParam( L, 2, ptP) Vector3d vtN ; LuaCheckParam( L, 3, vtN) int nDestGrpId ; LuaCheckParam( L, 4, nDestGrpId) int nRefType = RTY_DEFAULT ; LuaGetParam( L, 5, nRefType) ; LuaClearStack( L) ; // eseguo calcolo intersezione Plane3d plPlane ; plPlane.Set( ptP, vtN) ; int nCount ; int nFirstId = ExeVolZmapIntersPlane( nId, plPlane, nDestGrpId, nRefType, &nCount) ; // restituisco il risultato if ( nFirstId != GDB_ID_NULL) { LuaSetParam( L, nFirstId) ; LuaSetParam( L, nCount) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; } return 2 ; } //---------------------------------------------------------------------------- static int LuaVolZmapAvoidBox( lua_State* L) { // 3 o 4 parametri : nId, frBox, vtDiag [, nRefType] int nId ; LuaCheckParam( L, 1, nId) Frame3d frBox ; LuaCheckParam( L, 2, frBox) Vector3d vtDiag ; LuaCheckParam( L, 3, vtDiag) int nRefType = RTY_DEFAULT ; LuaGetParam( L, 4, nRefType) ; LuaClearStack( L) ; // eseguo calcolo profondità dal punto lungo la direzione bool bOk = ExeVolZmapAvoidBox( nId, frBox, vtDiag, nRefType) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- bool LuaInstallGdbModifyVol( LuaMgr& luaMgr) { bool bOk = ( &luaMgr != nullptr) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExplodeVolume", LuaExplodeVolume) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCopyVolZmapPart", LuaCopyVolZmapPart) ; bOk = bOk && luaMgr.RegisterFunction( "EgtRemoveVolZmapPart", LuaRemoveVolZmapPart) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapSetStdTool", LuaVolZmapSetStdTool) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapSetAdvTool", LuaVolZmapSetAdvTool) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapSetMortiserTool", LuaVolZmapSetMortiserTool) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapSetChiselTool", LuaVolZmapSetChiselTool) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapMillingStep", LuaVolZmapMillingStep) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapGetDepth", LuaVolZmapGetDepth) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapIntersPlane", LuaVolZmapIntersPlane) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapAvoidBox", LuaVolZmapAvoidBox) ; return bOk ; }