//---------------------------------------------------------------------------- // EgalTech 2020-2020 //---------------------------------------------------------------------------- // File : LUA_GdbGetCurve.cpp Data : 23.03.20 Versione : 2.2c3 // Contenuto : Funzioni di interrogazione delle curve per LUA. // // // // Modifiche : 23.03.20 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE_Const.h" #include "LUA.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkLuaAux.h" //---------------------------------------------------------------------------- static int LuaCurveDomain( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il dominio della curva double dStart, dEnd ; if ( ExeCurveDomain( nId, &dStart, &dEnd)) { LuaSetParam( L, dStart) ; LuaSetParam( L, dEnd) ; return 2 ; } else { LuaSetParam( L) ; return 1 ; } } //---------------------------------------------------------------------------- static int LuaCurveLength( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero la lunghezza della curva double dLen ; if ( ExeCurveLength( nId, &dLen)) LuaSetParam( L, dLen) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveParamAtLength( lua_State* L) { // 2 parametri : nId, dLen int nId ; LuaCheckParam( L, 1, nId) double dLen ; LuaCheckParam( L, 2, dLen) LuaClearStack( L) ; // recupero il parametro in corrispondenza di dLen double dPar ; if ( ExeCurveParamAtLength( nId, dLen, &dPar)) LuaSetParam( L, dPar) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveParamAtPoint( lua_State* L) { // 2 o 3 o 4 parametri : nId, pt [, dTol, nRefType] int nId ; LuaCheckParam( L, 1, nId) Point3d ptP ; LuaCheckParam( L, 2, ptP) double dTol = EPS_SMALL ; LuaGetParam( L, 3, dTol) ; int nRefType = RTY_DEFAULT ; LuaGetParam( L, 4, nRefType) ; LuaClearStack( L) ; // recupero il parametro in corrispondenza di pt double dPar ; if ( ExeCurveParamAtPoint( nId, ptP, dTol, nRefType, &dPar)) LuaSetParam( L, dPar) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveIsClosed( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // verifico se curva chiusa bool bClosed = ExeCurveIsClosed( nId) ; LuaSetParam( L, bClosed) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveIsFlat( lua_State* L) { // 1 o 2 parametri : Id [, dToler] int nId ; LuaCheckParam( L, 1, nId) double dToler = EPS_SMALL ; LuaGetParam( L, 2, dToler) ; LuaClearStack( L) ; // verifico se curva piatta e restituisco il piano medio Plane3d Plane ; bool bFlat = ExeCurveIsFlat( nId, Plane, false, dToler) ; LuaSetParam( L, bFlat) ; LuaSetParam( L, Plane.GetVersN()) ; LuaSetParam( L, Plane.GetDist()) ; return 3 ; } //---------------------------------------------------------------------------- static int LuaCurveIsACircle( lua_State* L) { // 1 o 2 parametri : Id [, dToler] int nId ; LuaCheckParam( L, 1, nId) double dToler = EPS_SMALL ; LuaGetParam( L, 2, dToler) ; LuaClearStack( L) ; // verifico se curva è equivalente ad una circonferenza Point3d ptCen ; Vector3d vtN ; double dRad ; bool bCCW ; bool bCircle = ExeCurveIsACircle( nId, ptCen, vtN, dRad, bCCW, dToler) ; LuaSetParam( L, bCircle) ; LuaSetParam( L, ptCen) ; LuaSetParam( L, vtN) ; LuaSetParam( L, dRad) ; LuaSetParam( L, bCCW) ; return 5 ; } //---------------------------------------------------------------------------- static int LuaCurveIsARectangle( lua_State* L) { // 1 o 2 parametri : Id [, dToler] int nId ; LuaCheckParam( L, 1, nId) double dToler = EPS_SMALL ; LuaGetParam( L, 2, dToler) ; LuaClearStack( L) ; // verifico se curva è equivalente ad un rettangolo Point3d ptP ; Vector3d vtL1 ; Vector3d vtL2 ; bool bRect = ExeCurveIsARectangle( nId, ptP, vtL1, vtL2, dToler) ; LuaSetParam( L, bRect) ; LuaSetParam( L, ptP) ; LuaSetParam( L, vtL1) ; LuaSetParam( L, vtL2) ; return 4 ; } //---------------------------------------------------------------------------- static int LuaCurveIsATrapezoid( lua_State* L) { // 1 o 2 parametri : Id [, dToler] int nId ; LuaCheckParam( L, 1, nId) double dToler = EPS_SMALL ; LuaGetParam( L, 2, dToler) ; LuaClearStack( L) ; // verifico se curva è equivalente ad un trapezio Point3d ptP ; Vector3d vtB1 ; Vector3d vtL1 ; Vector3d vtB2 ; bool bTrap = ExeCurveIsATrapezoid( nId, ptP, vtB1, vtL1, vtB2, dToler) ; LuaSetParam( L, bTrap) ; LuaSetParam( L, ptP) ; LuaSetParam( L, vtB1) ; LuaSetParam( L, vtL1) ; LuaSetParam( L, vtB2) ; return 5 ; } //---------------------------------------------------------------------------- static int LuaCurveAreaXY( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero l'area della curva proiettata sul piano XY double dArea ; if ( ExeCurveAreaXY( nId, dArea)) LuaSetParam( L, dArea) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveArea( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il piano medio della curva e la sua area su di esso Plane3d Plane ; double dArea ; if ( ExeCurveArea( nId, Plane, dArea)) { LuaSetParam( L, Plane.GetVersN()) ; LuaSetParam( L, Plane.GetDist()) ; LuaSetParam( L, dArea) ; return 3 ; } else { LuaSetParam( L) ; return 1 ; } } //---------------------------------------------------------------------------- static int LuaCurveExtrusion( lua_State* L) { // 1 o 2 parametri : Id [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nRefId = nId ; LuaGetParam( L, 2, nRefId) ; LuaClearStack( L) ; // recupero il versore Vector3d vtExtr ; if ( ExeCurveExtrusion( nId, nRefId, vtExtr)) LuaSetParam( L, vtExtr) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveThickness( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero lo spessore double dThick ; if ( ExeCurveThickness( nId, &dThick)) LuaSetParam( L, dThick) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveSelfIntersCount( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il numero di auto-intersezioni int nCount ; if ( ExeCurveSelfIntersCount( nId, &nCount)) LuaSetParam( L, nCount) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveMinAreaRectangleXY( lua_State* L) { // 1 o 2 parametri : Id [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nRefId = nId ; LuaGetParam( L, 2, nRefId) ; LuaClearStack( L) ; // recupero i dati del rettangolo Frame3d frRect ; double dDimX ; double dDimY ; bool bOk = ExeCurveMinAreaRectangleXY( nId, nRefId, frRect, dDimX, dDimY) ; if ( bOk) { LuaSetParam( L, frRect) ; LuaSetParam( L, dDimX) ; LuaSetParam( L, dDimY) ; return 3 ; } else { LuaSetParam( L) ; return 1 ; } } //---------------------------------------------------------------------------- static int LuaGetCurveLinearConvexHullXY( lua_State* L) { // 1 o 2 o 3 parametri : nId [, dLinTol [, nRefType]] int nId ; LuaCheckParam( L, 1, nId) double dLinTol = LIN_TOL_STD ; LuaGetParam( L, 2, dLinTol) ; int nRefType = RTY_DEFAULT ; LuaGetParam( L, 3, nRefType) ; LuaClearStack( L) ; // calcolo il convex hull della curva nel piano XY del riferimento indicato int nNewId = ExeGetCurveLinearConvexHullXY( nId, dLinTol, nRefType) ; if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveWithRegionClassify( lua_State* L) { // 2 parametri : nCurveId, nRegionId int nCurveId ; LuaCheckParam( L, 1, nCurveId) int nRegionId ; LuaCheckParam( L, 2, nRegionId) ; LuaClearStack( L) ; // eseguo la classificazione int nRes = ExeCurveWithRegionClassify( nCurveId, nRegionId) ; if ( nRes != CRC_NULL) LuaSetParam( L, nRes) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaArcRadius( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il raggio double dRad ; if ( ExeArcRadius( nId, &dRad)) LuaSetParam( L, dRad) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaArcAngCenter( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero l'angolo al centro in gradi double pdAngDeg ; if ( ExeArcAngCenter( nId, &pdAngDeg)) LuaSetParam( L, pdAngDeg) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaArcDeltaN( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il delta su normale al suo piano double dDeltaN ; if ( ExeArcDeltaN( nId, &dDeltaN)) LuaSetParam( L, dDeltaN) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaArcNormVersor( lua_State* L) { // 1 o 2 parametri : Id [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nRefId = nId ; LuaGetParam( L, 2, nRefId) ; LuaClearStack( L) ; // recupero il versore Vector3d vtNorm ; if ( ExeArcNormVersor( nId, nRefId, vtNorm)) LuaSetParam( L, vtNorm) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveCompoLength( lua_State* L) { // 2 parametri : Id, nCrv int nId ; LuaCheckParam( L, 1, nId) int nCrv ; LuaCheckParam( L, 2, nCrv) LuaClearStack( L) ; // recupero il centro della curva semplice indicizzata double dLen ; if ( ExeCurveCompoLength( nId, nCrv, dLen)) LuaSetParam( L, dLen) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveCompoCenter( lua_State* L) { // 2 o 3 parametri : Id, nCrv [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nCrv ; LuaCheckParam( L, 2, nCrv) int nRefId = nId ; LuaGetParam( L, 3, nRefId) ; LuaClearStack( L) ; // recupero il centro della curva semplice indicizzata Point3d ptCen ; if ( ExeCurveCompoCenter( nId, nCrv, nRefId, ptCen)) LuaSetParam( L, ptCen) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveCompoRadius( lua_State* L) { // 2 parametri : Id, nCrv int nId ; LuaCheckParam( L, 1, nId) int nCrv ; LuaCheckParam( L, 2, nCrv) LuaClearStack( L) ; // recupero il raggio della curva semplice indicizzata double dRadius ; if ( ExeCurveCompoRadius( nId, nCrv, dRadius)) LuaSetParam( L, dRadius) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveCompoAngCenter( lua_State* L) { // 2 parametri : Id, nCrv int nId ; LuaCheckParam( L, 1, nId) int nCrv ; LuaCheckParam( L, 2, nCrv) LuaClearStack( L) ; // recupero l'angolo al centro della curva semplice indicizzata double dAngCen ; if ( ExeCurveCompoAngCenter( nId, nCrv, dAngCen)) LuaSetParam( L, dAngCen) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaCurveCompoNormVersor( lua_State* L) { // 2 o 3 parametri : Id, nCrv [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nCrv ; LuaCheckParam( L, 2, nCrv) int nRefId = nId ; LuaGetParam( L, 3, nRefId) ; LuaClearStack( L) ; // recupero l'angolo al centro della curva semplice indicizzata Vector3d vtNorm ; if ( ExeCurveCompoNormVersor( nId, nCrv, nRefId, vtNorm)) LuaSetParam( L, vtNorm) ; else LuaSetParam( L) ; return 1 ; } //------------------------------------------------------------------------------- bool LuaInstallGdbGetCurve( LuaMgr& luaMgr) { bool bOk = ( &luaMgr != nullptr) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveDomain", LuaCurveDomain) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveLength", LuaCurveLength) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveParamAtLength", LuaCurveParamAtLength) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveParamAtPoint", LuaCurveParamAtPoint) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveIsClosed", LuaCurveIsClosed) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveIsFlat", LuaCurveIsFlat) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveIsACircle", LuaCurveIsACircle) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveIsARectangle", LuaCurveIsARectangle) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveIsATrapezoid", LuaCurveIsATrapezoid) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveAreaXY", LuaCurveAreaXY) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveArea", LuaCurveArea) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveExtrusion", LuaCurveExtrusion) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveThickness", LuaCurveThickness) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveSelfIntersCount", LuaCurveSelfIntersCount) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveMinAreaRectangleXY", LuaCurveMinAreaRectangleXY) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetCurveLinearConvexHullXY", LuaGetCurveLinearConvexHullXY) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveWithRegionClassify", LuaCurveWithRegionClassify) ; bOk = bOk && luaMgr.RegisterFunction( "EgtArcRadius", LuaArcRadius) ; bOk = bOk && luaMgr.RegisterFunction( "EgtArcAngCenter", LuaArcAngCenter) ; bOk = bOk && luaMgr.RegisterFunction( "EgtArcDeltaN", LuaArcDeltaN) ; bOk = bOk && luaMgr.RegisterFunction( "EgtArcNormVersor", LuaArcNormVersor) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoLength", LuaCurveCompoLength) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoCenter", LuaCurveCompoCenter) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoRadius", LuaCurveCompoRadius) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoAngCenter", LuaCurveCompoAngCenter) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoNormVersor", LuaCurveCompoNormVersor) ; return bOk ; }