//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : LUA_GdbCreateCurve.cpp Data : 07.01.15 Versione : 1.6a1 // Contenuto : Funzioni di creazione curve per LUA. // // // // Modifiche : 07.01.15 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "LUA.h" #include "API.h" #include "AuxTools.h" #include "/EgtDev/Include/EInAPI.h" #include "/EgtDev/Include/EInConst.h" #include "/EgtDev/Include/EgkPolyLine.h" #include "/EgtDev/Include/EgnStringUtils.h" #include "/EgtDev/Extern/Lua/Include/lua.hpp" using namespace std ; //------------------------------------------------------------------------------- static int LuaCreateCurveLine( lua_State* L) { // 3 o 4 parametri : ParentId, PtIni, PtFin [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) Point3d ptIni ; LuaCheckParam( L, 2, ptIni) Point3d ptFin ; LuaCheckParam( L, 3, ptFin) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 4, nRefType) ; LuaClearStack( L) ; // creo il segmento di retta int nId = EgtCreateCurveLine( nParentId, ptIni.v, ptFin.v, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveLineEx( lua_State* L) { // 7 o 8 parametri : ParentId, PtIni, sSepI, nIdI, PtFin, sSEpF, nIdF [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) Point3d ptIni ; LuaCheckParam( L, 2, ptIni) string sSepI ; LuaCheckParam( L, 3, sSepI) int nIdI ; LuaCheckParam( L, 4, nIdI) Point3d ptFin ; LuaCheckParam( L, 5, ptFin) string sSepF ; LuaCheckParam( L, 6, sSepF) int nIdF ; LuaCheckParam( L, 7, nIdF) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 8, nRefType) ; LuaClearStack( L) ; // creo il segmento di retta int nId = EgtCreateCurveLineEx( nParentId, ptIni.v, StringToSep( sSepI), nIdI, ptFin.v, StringToSep( sSepF), nIdF, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveLinePVL( lua_State* L) { // 4 o 5 parametri : ParentId, PtIni, VtDir, dLen [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) Point3d ptIni ; LuaCheckParam( L, 2, ptIni) Vector3d vtDir ; LuaCheckParam( L, 3, vtDir) double dLen ; LuaCheckParam( L, 4, dLen) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 5, nRefType) ; LuaClearStack( L) ; // creo il segmento di retta int nId = EgtCreateCurveLinePVL( nParentId, ptIni.v, vtDir.v, dLen, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveLineMinPointCurve( lua_State* L) { // 3 o 4 o 5 parametri : ParentId, PtIni, CrvId [, NearPar] [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) Point3d ptIni ; LuaCheckParam( L, 2, ptIni) int nCrvId ; LuaCheckParam( L, 3, nCrvId) double dNearPar = 0 ; int nRefType = RTY_DEFAULT ; if ( LuaGetParam( L, 4, dNearPar)) LuaGetRefType( L, 5, nRefType) ; else LuaGetRefType( L, 4, nRefType) ; LuaClearStack( L) ; // creo il segmento di retta int nId = EgtCreateCurveLineMinPointCurve( nParentId, ptIni.v, nCrvId, dNearPar, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveCircle( lua_State* L) { // 4 o 5 parametri : ParentId, PtCen, VtN, Rad [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) Point3d ptCen ; LuaCheckParam( L, 2, ptCen) Vector3d vtN ; LuaCheckParam( L, 3, vtN) double dRad ; LuaCheckParam( L, 4, dRad) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 5, nRefType) ; LuaClearStack( L) ; // creo l'arco int nId = EgtCreateCurveCircle( nParentId, ptCen.v, vtN.v, dRad, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveCircleCPN( lua_State* L) { // 4 o 5 parametri : ParentId, PtCen, PtOn, VtN [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) Point3d ptCen ; LuaCheckParam( L, 2, ptCen) Point3d ptOn ; LuaCheckParam( L, 3, ptOn) Vector3d vtN ; LuaCheckParam( L, 4, vtN) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 5, nRefType) ; LuaClearStack( L) ; // creo l'arco int nId = EgtCreateCurveCircleCPN( nParentId, ptCen.v, ptOn.v, vtN.v, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveCircle3P( lua_State* L) { // 4 o 5 parametri : ParentId, PtP1, PtP2, PtP3 [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) Point3d ptP1 ; LuaCheckParam( L, 2, ptP1) Point3d ptP2 ; LuaCheckParam( L, 3, ptP2) Point3d ptP3 ; LuaCheckParam( L, 4, ptP3) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 5, nRefType) ; LuaClearStack( L) ; // creo l'arco int nId = EgtCreateCurveCircle3P( nParentId, ptP1.v, ptP2.v, ptP3.v, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveArc( lua_State* L) { // 7 o 8 parametri : ParentId, PtCen, VtN, Rad, VtS, AngCenDeg, DeltaN [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) Point3d ptCen ; LuaCheckParam( L, 2, ptCen) Vector3d vtN ; LuaCheckParam( L, 3, vtN) double dRad ; LuaCheckParam( L, 4, dRad) Vector3d vtS ; LuaCheckParam( L, 5, vtS) double dAngCenDeg ; LuaCheckParam( L, 6, dAngCenDeg) double dDeltaN ; LuaCheckParam( L, 7, dDeltaN) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 8, nRefType) ; LuaClearStack( L) ; // creo l'arco int nId = EgtCreateCurveArc( nParentId, ptCen.v, vtN.v, dRad, vtS.v, dAngCenDeg, dDeltaN, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveArcC2PN( lua_State* L) { // 5 o 6 parametri : ParentId, PtCen, PtStart, PtNearEnd, VtNorm [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) Point3d ptCen ; LuaCheckParam( L, 2, ptCen) Point3d ptStart ; LuaCheckParam( L, 3, ptStart) Point3d ptNearEnd ; LuaCheckParam( L, 4, ptNearEnd) Vector3d vtNorm ; LuaCheckParam( L, 5, vtNorm) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 6, nRefType) ; LuaClearStack( L) ; // creo l'arco int nId = EgtCreateCurveArcC2PN( nParentId, ptCen.v, ptStart.v, ptNearEnd.v, vtNorm.v, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveArc3P( lua_State* L) { // 4 o 5 parametri : ParentId, PtP1, PtP2, PtP3 [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) Point3d ptP1 ; LuaCheckParam( L, 2, ptP1) Point3d ptP2 ; LuaCheckParam( L, 3, ptP2) Point3d ptP3 ; LuaCheckParam( L, 4, ptP3) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 5, nRefType) ; LuaClearStack( L) ; // creo l'arco int nId = EgtCreateCurveArc3P( nParentId, ptP1.v, ptP2.v, ptP3.v, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveArc2PVN( lua_State* L) { // 5 o 6 parametri : ParentId, PtStart, PtEnd, VtDirS, VtNorm [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) Point3d ptStart ; LuaCheckParam( L, 2, ptStart) Point3d ptEnd ; LuaCheckParam( L, 3, ptEnd) Vector3d vtDirS ; LuaCheckParam( L, 4, vtDirS) Vector3d vtNorm ; LuaCheckParam( L, 5, vtNorm) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 6, nRefType) ; LuaClearStack( L) ; // creo l'arco int nId = EgtCreateCurveArc2PVN( nParentId, ptStart.v, ptEnd.v, vtDirS.v, vtNorm.v, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveBezier( lua_State* L) { // 3 o 4 parametri : ParentId, Degree, CtrlPnts [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) int nDegree ; LuaCheckParam( L, 2, nDegree) PNTVECTOR vPnt ; LuaCheckParam( L, 3, vPnt) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 4, nRefType) ; LuaClearStack( L) ; // creo la curva int nId = EgtCreateCurveBezier( nParentId, nDegree, vPnt, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveBezierRational( lua_State* L) { // 3 o 4 parametri : ParentId, Degree, CtrlPntWs [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) int nDegree ; LuaCheckParam( L, 2, nDegree) PNTUVECTOR vPntW ; LuaCheckParam( L, 3, vPntW) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 4, nRefType) ; LuaClearStack( L) ; // creo la curva int nId = EgtCreateCurveBezierRational( nParentId, nDegree, vPntW, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveBezierFromArc( lua_State* L) { // 2 o 3 parametri : ParentId, ArcId[ , Erase] int nParentId ; LuaCheckParam( L, 1, nParentId) int nArcId ; LuaCheckParam( L, 2, nArcId) bool bErase = true ; if ( lua_gettop( L) >= 3) LuaCheckParam( L, 3, bErase) ; LuaClearStack( L) ; // creo la curva int nId = EgtCreateCurveBezierFromArc( nParentId, nArcId, bErase) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveCompo( lua_State* L) { // 2 o 3 parametri : ParentId, nIds [, Erase] int nParentId ; LuaCheckParam( L, 1, nParentId) INTVECTOR vIds ; LuaCheckParam( L, 2, vIds) bool bErase = true ; if ( lua_gettop( L) >= 3) LuaCheckParam( L, 3, bErase) ; LuaClearStack( L) ; // creo la curva composita int nId = EgtCreateCurveCompo( nParentId, vIds, bErase) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveCompoByChain( lua_State* L) { // 3 o 4 o 5 parametri : ParentId, nIds, PtNear [, Erase] [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) INTVECTOR vIds ; LuaCheckParam( L, 2, vIds) Point3d ptNear ; LuaCheckParam( L, 3, ptNear) bool bErase = true ; int nRefType = RTY_DEFAULT ; if ( LuaGetParam( L, 4, bErase)) LuaGetRefType( L, 5, nRefType) ; else LuaGetRefType( L, 4, nRefType) ; LuaClearStack( L) ; // creo la curva composita int nId = EgtCreateCurveCompoByChain( nParentId, vIds, ptNear, bErase, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveCompoFromPoints( lua_State* L) { // 2 o 3 parametri : ParentId, ptPs [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) PNTVECTOR vPnt ; LuaCheckParam( L, 2, vPnt) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 3, nRefType) ; LuaClearStack( L) ; PolyLine PL ; // creo una polilinea a partire dai punti for ( size_t i = 0 ; i < vPnt.size() ; ++ i) PL.AddUPoint( 0, vPnt[i]) ; // creo la curva composita int nId = EgtCreateCurveCompoFromPoints( nParentId, PL, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveCompoFromPointBulges( lua_State* L) { // 2 o 3 parametri : ParentId, ptPBs [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) PNTUVECTOR vPntB ; LuaCheckParam( L, 2, vPntB) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 3, nRefType) ; LuaClearStack( L) ; // creo un poliarco a partire dai punti con bulge PolyArc PA ; for ( size_t i = 0 ; i < vPntB.size() ; ++ i) PA.AddUPoint( 0, vPntB[i].first, vPntB[i].second) ; // creo la curva composita int nId = EgtCreateCurveCompoFromPointBulges( nParentId, PA, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateCurveCompoByApprox( lua_State* L) { // 3 o 4 parametri : ParentId, nSouId, sType [, dLinTol] int nParentId ; LuaCheckParam( L, 1, nParentId) int nSouId ; LuaCheckParam( L, 2, nSouId) bool bArcsVsLines = true ; string sTemp ; LuaCheckParam( L, 3, sTemp) ToUpper( sTemp) ; if ( sTemp == "LINES") bArcsVsLines = false ; double dLinTol = 0.01 ; if ( lua_gettop( L) >= 4) LuaCheckParam( L, 4, dLinTol) LuaClearStack( L) ; // creo la curva composita int nId = EgtCreateCurveCompoByApprox( nParentId, nSouId, bArcsVsLines, dLinTol) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreateRectangle3P( lua_State* L) { // 4 o 5 parametri : ParentId, PtIni, PtCross, PtDir [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) Point3d ptIni ; LuaCheckParam( L, 2, ptIni) Point3d ptCross ; LuaCheckParam( L, 3, ptCross) Point3d ptDir ; LuaCheckParam( L, 4, ptDir) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 5, nRefType) ; LuaClearStack( L) ; // creo il poligono int nId = EgtCreateRectangle3P( nParentId, ptIni.v, ptCross.v, ptDir.v, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreatePolygonFromRadius( lua_State* L) { // 5 o 6 parametri : ParentId, nNumSides, PtCen, PtCorn, VtN [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) int nNumSides ; LuaCheckParam( L, 2, nNumSides) Point3d PtCen ; LuaCheckParam( L, 3, PtCen) Point3d PtCorn ; LuaCheckParam( L, 4, PtCorn) Vector3d vtN ; LuaCheckParam( L, 5, vtN) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 6, nRefType) ; LuaClearStack( L) ; // creo il poligono int nId = EgtCreatePolygonFromRadius( nParentId, nNumSides, PtCen.v, PtCorn.v, vtN.v, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreatePolygonFromApothem( lua_State* L) { // 5 o 6 parametri : ParentId, nNumSides, PtCen, PtMid, VtN [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) int nNumSides ; LuaCheckParam( L, 2, nNumSides) Point3d PtCen ; LuaCheckParam( L, 3, PtCen) Point3d PtMid ; LuaCheckParam( L, 4, PtMid) Vector3d vtN ; LuaCheckParam( L, 5, vtN) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 6, nRefType) ; LuaClearStack( L) ; // creo il poligono int nId = EgtCreatePolygonFromApothem( nParentId, nNumSides, PtCen.v, PtMid.v, vtN.v, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- static int LuaCreatePolygonFromSide( lua_State* L) { // 5 o 6 parametri : ParentId, nNumSides, PtIni, PtFin, VtN [, sRefType] int nParentId ; LuaCheckParam( L, 1, nParentId) int nNumSides ; LuaCheckParam( L, 2, nNumSides) Point3d ptIni ; LuaCheckParam( L, 3, ptIni) Point3d ptFin ; LuaCheckParam( L, 4, ptFin) Vector3d vtN ; LuaCheckParam( L, 5, vtN) int nRefType = RTY_DEFAULT ; LuaGetRefType( L, 6, nRefType) ; LuaClearStack( L) ; // creo il poligono int nId = EgtCreatePolygonFromSide( nParentId, nNumSides, ptIni.v, ptFin.v, vtN.v, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) LuaSetReturn( L, nId) ; else LuaSetReturn( L) ; return 1 ; } //------------------------------------------------------------------------------- bool LuaInstallGdbCreateCurve( lua_State* L) { try { lua_register( L, "EgtLine", LuaCreateCurveLine) ; lua_register( L, "EgtLineEx", LuaCreateCurveLineEx) ; lua_register( L, "EgtLinePVL", LuaCreateCurveLinePVL) ; lua_register( L, "EgtLineMinPointCurve", LuaCreateCurveLineMinPointCurve) ; lua_register( L, "EgtCircle", LuaCreateCurveCircle) ; lua_register( L, "EgtCircleCPN", LuaCreateCurveCircleCPN) ; lua_register( L, "EgtCircle3P", LuaCreateCurveCircle3P) ; lua_register( L, "EgtArc", LuaCreateCurveArc) ; lua_register( L, "EgtArcC2PN", LuaCreateCurveArcC2PN) ; lua_register( L, "EgtArc3P", LuaCreateCurveArc3P) ; lua_register( L, "EgtArc2PVN", LuaCreateCurveArc2PVN) ; lua_register( L, "EgtCurveBezier", LuaCreateCurveBezier) ; lua_register( L, "EgtCurveBezierRat", LuaCreateCurveBezierRational) ; lua_register( L, "EgtCurveBezierFromArc", LuaCreateCurveBezierFromArc) ; lua_register( L, "EgtCurveCompo", LuaCreateCurveCompo) ; lua_register( L, "EgtCurveCompoByChain", LuaCreateCurveCompoByChain) ; lua_register( L, "EgtCurveCompoFromPoints", LuaCreateCurveCompoFromPoints) ; lua_register( L, "EgtCurveCompoFromPointBulges", LuaCreateCurveCompoFromPointBulges) ; lua_register( L, "EgtCurveCompoByApprox", LuaCreateCurveCompoByApprox) ; lua_register( L, "EgtRectangle3P", LuaCreateRectangle3P) ; lua_register( L, "EgtPolygonFromRadius", LuaCreatePolygonFromRadius) ; lua_register( L, "EgtPolygonFromApothem", LuaCreatePolygonFromApothem) ; lua_register( L, "EgtPolygonFromSide", LuaCreatePolygonFromSide) ; } catch ( ...) { return false ; } return true ; }