//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : LUA_GeoSnap.cpp Data : 02.10.14 Versione : 1.5i5 // Contenuto : Funzioni di snap ad oggetti del DB geometrico per LUA. // // // // Modifiche : 02.10.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "LUA.h" #include "API.h" #include "/EgtDev/Include/EInAPI.h" #include "/EgtDev/Extern/Lua/Include/lua.hpp" using namespace std ; //---------------------------------------------------------------------------- static int LuaStartPoint( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il punto iniziale dell'entità Point3d ptP ; if ( EgtStartPoint( nId, ptP.v)) LuaSetReturn( L, ptP) ; else LuaSetReturn( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaEndPoint( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il punto finale dell'entità Point3d ptP ; if ( EgtEndPoint( nId, ptP.v)) LuaSetReturn( L, ptP) ; else LuaSetReturn( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaMidPoint( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il punto centrale dell'entità Point3d ptP ; if ( EgtMidPoint( nId, ptP.v)) LuaSetReturn( L, ptP) ; else LuaSetReturn( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCenterPoint( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il punto centrale dell'entità Point3d ptP ; if ( EgtCenterPoint( nId, ptP.v)) LuaSetReturn( L, ptP) ; else LuaSetReturn( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaAtParamPoint( lua_State* L) { // 2 parametri : Id, U int nId ; LuaCheckParam( L, 1, nId) double dU ; LuaCheckParam( L, 2, dU) LuaClearStack( L) ; // recupero il punto in posizione parametrica U della curva Point3d ptP ; if ( EgtAtParamPoint( nId, dU, ptP.v)) LuaSetReturn( L, ptP) ; else LuaSetReturn( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaStartVector( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il vettore tangente all'inizio della curva Vector3d vtV ; if ( EgtStartVector( nId, vtV.v)) LuaSetReturn( L, vtV) ; else LuaSetReturn( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaEndVector( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il vettore tangente alla fine della curva Vector3d vtV ; if ( EgtEndVector( nId, vtV.v)) LuaSetReturn( L, vtV) ; else LuaSetReturn( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaMidVector( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il vettore tangente nel punto medio della curva Vector3d vtV ; if ( EgtMidVector( nId, vtV.v)) LuaSetReturn( L, vtV) ; else LuaSetReturn( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaAtParamVector( lua_State* L) { // 2 o 3 parametri : Id, U [, sSide] int nId ; LuaCheckParam( L, 1, nId) double dU ; LuaCheckParam( L, 2, dU) int nSide = + 1 ; string sSide ; if ( LuaGetParam( L, 3, sSide) && sSide == "-") nSide = - 1 ; LuaClearStack( L) ; // recupero il punto in posizione parametrica U della curva Vector3d vtV ; if ( EgtAtParamVector( nId, dU, nSide, vtV.v)) LuaSetReturn( L, vtV) ; else LuaSetReturn( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaFrame( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il frame Frame3d frFrame ; if ( EgtFrame( nId, frFrame)) LuaSetReturn( L, frFrame) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- bool LuaInstallGeoSnap( lua_State* L) { try { lua_register( L, "EgtSP", LuaStartPoint) ; lua_register( L, "EgtEP", LuaEndPoint) ; lua_register( L, "EgtMP", LuaMidPoint) ; lua_register( L, "EgtCP", LuaCenterPoint) ; lua_register( L, "EgtUP", LuaAtParamPoint) ; lua_register( L, "EgtSV", LuaStartVector) ; lua_register( L, "EgtEV", LuaEndVector) ; lua_register( L, "EgtMV", LuaMidVector) ; lua_register( L, "EgtUV", LuaAtParamVector) ; lua_register( L, "EgtFR", LuaFrame) ; } catch ( ...) { return false ; } return true ; }