//---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- // File : LUA_GdbModifySurf.cpp Data : 09.03.15 Versione : 1.6b6 // Contenuto : Funzioni di modifica delle superfici per LUA. // // // // Modifiche : 09.03.15 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "LUA.h" #include "EXE_Const.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkCurve.h" #include "/EgtDev/Include/EGkGdbConst.h" #include "/EgtDev/Include/EGkLuaAux.h" using namespace std ; //---------------------------------------------------------------------------- static int LuaInvertSurf( lua_State* L) { // 1 parametro : Id/s INTVECTOR vId ; LuaCheckParam( L, 1, vId) LuaClearStack( L) ; // eseguo inversione superfici bool bOk = ExeInvertSurface( vId) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaExplodeSurf( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // esplosione della superficie int nCount ; int nFirstId = ExeExplodeSurface( nId, &nCount) ; if ( nFirstId != GDB_ID_NULL) LuaSetParam( L, nFirstId) ; else LuaSetParam( L) ; LuaSetParam( L, nCount) ; return 2 ; } //------------------------------------------------------------------------------- static int LuaApproxSurf( lua_State* L) { // 1 o 2 parametri : Id [, dLinTol] int nId ; LuaCheckParam( L, 1, nId) double dLinTol = LIN_TOL_SRF ; LuaGetParam( L, 2, dLinTol) ; LuaClearStack( L) ; // approssimazione della superficie bool bOk = ExeApproxSurface( nId, dLinTol) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSurfFrAdd( lua_State* L) { // 2 parametro : Id1, Id2 int nId1 ; LuaCheckParam( L, 1, nId1) int nId2 ; LuaCheckParam( L, 2, nId2) LuaClearStack( L) ; // unisco alla prima regione la seconda bool bOk = ExeSurfFrAdd( nId1, nId2) ; LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSurfFrSubtract( lua_State* L) { // 2 parametro : Id1, Id2 int nId1 ; LuaCheckParam( L, 1, nId1) int nId2 ; LuaCheckParam( L, 2, nId2) LuaClearStack( L) ; // sottraggo dalla prima regione la seconda bool bOk = ExeSurfFrSubtract( nId1, nId2) ; LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSurfFrIntersect( lua_State* L) { // 2 parametro : Id1, Id2 int nId1 ; LuaCheckParam( L, 1, nId1) int nId2 ; LuaCheckParam( L, 2, nId2) LuaClearStack( L) ; // interseco la prima regione con la seconda bool bOk = ExeSurfFrIntersect( nId1, nId2) ; LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSurfFrOffset( lua_State* L) { // 3 parametri : Id, dDist, nType int nId ; LuaCheckParam( L, 1, nId) double dDist ; LuaCheckParam( L, 2, dDist) int nType = ICurve::OFF_FILLET ; LuaGetParam( L, 3, nType) ; LuaClearStack( L) ; // eseguo l'offset della regione bool bOk = ExeSurfFrOffset( nId, dDist, nType) ; LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmMoveVertex( lua_State* L) { // 3 o 4 o 5 parametri : nId, nVert, ptNewVert [, nRefId] [, bUpdate] int nId ; LuaCheckParam( L, 1, nId) int nVert ; LuaCheckParam( L, 2, nVert) Point3d ptNewVert ; LuaCheckParam( L, 3, ptNewVert) int nRefType = RTY_DEFAULT ; bool bUpdate = true ; if ( LuaGetParam( L, 4, nRefType)) LuaGetParam( L, 5, bUpdate) ; else LuaGetParam( L, 4, bUpdate) ; LuaClearStack( L) ; // sposto il vertice di indice dato della trimesh bool bOk = ExeSurfTmMoveVertex( nId, nVert, ptNewVert, nRefType, bUpdate) ; LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmToTriangles( lua_State* L) { // 1 parametro : nId int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // esplosione della trimesh in triangoli int nCount ; int nFirstId = ExeSurfTmToTriangles( nId, &nCount) ; if ( nFirstId != GDB_ID_NULL) LuaSetParam( L, nFirstId) ; else LuaSetParam( L) ; LuaSetParam( L, nCount) ; return 2 ; } //---------------------------------------------------------------------------- static int LuaSurfTmRemoveFacet( lua_State* L) { // 2 parametri : nId, nFacet int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) LuaClearStack( L) ; // eseguo rimozione della faccia dalla superficie bool bOk = ExeSurfTmRemoveFacet( nId, nFacet) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmSwapFacets( lua_State* L) { // 3 parametri : nId, nFacet1, nFacet2 int nId ; LuaCheckParam( L, 1, nId) int nFacet1 ; LuaCheckParam( L, 2, nFacet1) int nFacet2 ; LuaCheckParam( L, 3, nFacet2) LuaClearStack( L) ; // eseguo scambio facce della superficie bool bOk = ExeSurfTmSwapFacets( nId, nFacet1, nFacet2) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmRemovePart( lua_State* L) { // 2 parametri : nId, nPart int nId ; LuaCheckParam( L, 1, nId) int nPart ; LuaCheckParam( L, 2, nPart) LuaClearStack( L) ; // eseguo rimozione della parte dalla superficie bool bOk = ExeSurfTmRemovePart( nId, nPart) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCutSurfTmPlane( lua_State* L) { // 4 o 5 parametri : Id, ptOn, vtN, bSaveOnEq [, nRefType] int nId ; LuaCheckParam( L, 1, nId) Point3d ptOn ; LuaCheckParam( L, 2, ptOn) Vector3d vtN ; LuaCheckParam( L, 3, vtN) bool bSaveOnEq ; LuaGetParam( L, 4, bSaveOnEq) ; int nRefType = RTY_DEFAULT ; LuaGetParam( L, 5, nRefType) ; LuaClearStack( L) ; // taglio la superficie con ilpiano bool bOk = ExeCutSurfTmPlane( nId, ptOn, vtN, bSaveOnEq, nRefType) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCutSurfTmClosedCurve( lua_State* L) { // 3 parametri : SurfId, CurveId, bSaveOnEq int nSurfId ; LuaCheckParam( L, 1, nSurfId) int nCurveId ; LuaCheckParam( L, 2, nCurveId) bool bSaveOnEq ; LuaGetParam( L, 3, bSaveOnEq) ; LuaClearStack( L) ; // taglio la superficie con ilpiano bool bOk = ExeCutSurfTmClosedCurve( nSurfId, nCurveId, bSaveOnEq) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSurfTmAdd( lua_State* L) { // 2 o 3 parametri : Id1, Id2 [, bTwoColors] int nId1 ; LuaCheckParam( L, 1, nId1) int nId2 ; LuaCheckParam( L, 2, nId2) bool bTwoColors = false ; LuaGetParam( L, 3, bTwoColors) ; LuaClearStack( L) ; // unisco alla prima superficie la seconda bool bOk = ExeSurfTmAdd( nId1, nId2, bTwoColors) ; LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSurfTmSubtract( lua_State* L) { // 2 o 3 parametri : Id1, Id2 [, bTwoColors] int nId1 ; LuaCheckParam( L, 1, nId1) int nId2 ; LuaCheckParam( L, 2, nId2) bool bTwoColors = false ; LuaGetParam( L, 3, bTwoColors) ; LuaClearStack( L) ; // sottraggo dalla prima superficie la seconda bool bOk = ExeSurfTmSubtract( nId1, nId2, bTwoColors) ; LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSurfTmIntersect( lua_State* L) { // 2 o 3 parametri : Id1, Id2 [, bTwoColors] int nId1 ; LuaCheckParam( L, 1, nId1) int nId2 ; LuaCheckParam( L, 2, nId2) bool bTwoColors = false ; LuaGetParam( L, 3, bTwoColors) ; LuaClearStack( L) ; // interseco la prima superficie con la seconda bool bOk = ExeSurfTmIntersect( nId1, nId2, bTwoColors) ; LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSurfTmResetTwoColors( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // eseguo reset TFlag per annullare due colori bool bOk = ExeSurfTmResetTwoColors( nId) ; LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaSurfTmSplit( lua_State* L) { // 2 parametri : nId, nSplitterId int nId ; LuaCheckParam( L, 1, nId) int nSplitterId ; LuaCheckParam( L, 2, nSplitterId) LuaClearStack( L) ; // divido la prima superficie in base alla seconda int nCount ; int nFirstId = ExeSurfTmSplit( nId, nSplitterId, &nCount) ; if ( nFirstId != GDB_ID_NULL) LuaSetParam( L, nFirstId) ; else LuaSetParam( L) ; LuaSetParam( L, nCount) ; return 2 ; } //------------------------------------------------------------------------------- static int LuaSurfTmCut( lua_State* L) { // 4 parametri : nId, nCutterId, bInVsOut, bOn int nId ; LuaCheckParam( L, 1, nId) int nCutterId ; LuaCheckParam( L, 2, nCutterId) bool bInVsOut ; LuaCheckParam( L, 3, bInVsOut) bool bOn ; LuaCheckParam( L, 4, bOn) LuaClearStack( L) ; // taglio la prima superficie in base alla seconda bool bOk = ExeSurfTmCut( nId, nCutterId, bInVsOut, bOn) ; LuaSetParam( L, bOk) ; return 1 ; } //------------------------------------------------------------------------------- bool LuaInstallGdbModifySurf( LuaMgr& luaMgr) { bool bOk = ( &luaMgr != nullptr) ; bOk = bOk && luaMgr.RegisterFunction( "EgtInvertSurf", LuaInvertSurf) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExplodeSurf", LuaExplodeSurf) ; bOk = bOk && luaMgr.RegisterFunction( "EgtApproxSurf", LuaApproxSurf) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrAdd", LuaSurfFrAdd) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrSubtract", LuaSurfFrSubtract) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrIntersect", LuaSurfFrIntersect) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrOffset", LuaSurfFrOffset) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmMoveVertex", LuaSurfTmMoveVertex) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmToTriangles", LuaSurfTmToTriangles) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmRemoveFacet", LuaSurfTmRemoveFacet) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmSwapFacets", LuaSurfTmSwapFacets) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmRemovePart", LuaSurfTmRemovePart) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCutSurfTmPlane", LuaCutSurfTmPlane) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCutSurfTmClosedCurve", LuaCutSurfTmClosedCurve) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmAdd", LuaSurfTmAdd) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmSubtract", LuaSurfTmSubtract) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmIntersect", LuaSurfTmIntersect) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmResetTwoColors", LuaSurfTmResetTwoColors) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmSplit", LuaSurfTmSplit) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmCut", LuaSurfTmCut) ; return bOk ; }