From ff50f8a808a6d8e28df724f9c253873a36fc4bfe Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Thu, 27 Mar 2025 08:53:21 +0100 Subject: [PATCH] - aggiunte funzioni Lua per copiare una sottocurva di una compo e per la CopyParamRange di una curva generica. --- EXE_GdbGetCurve.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++ LUA_GdbGetCurve.cpp | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/EXE_GdbGetCurve.cpp b/EXE_GdbGetCurve.cpp index 8ae68a6..46c3bf5 100644 --- a/EXE_GdbGetCurve.cpp +++ b/EXE_GdbGetCurve.cpp @@ -17,6 +17,7 @@ #include "EXE_Const.h" #include "EXE_Macro.h" #include "GeoTools.h" +#include "/EgtDev/Include/EgtNumUtils.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkGeoPoint3d.h" @@ -846,4 +847,63 @@ ExeCurveMaxOffset( int nId, double& dMaxOffset) // recupero la curva const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ; return CalcCurveLimitOffset( *pCrv, dMaxOffset) ; +} + +//---------------------------------------------------------------------------- +int +ExeCopyCompoSubCurve( int nCrvId, int nSubCrvToCopy, int nDestGrpId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva compo + const ICurveComposite* pCompo = GetCurveComposite( pGeomDB->GetGeoObj( nCrvId)) ; + if ( pCompo == nullptr) + return GDB_ID_NULL ; + // recupero il riferimento della curva + Frame3d frCrv ; + bool bOk = true ; + bOk = bOk && pGeomDB->GetGlobFrame( nCrvId, frCrv) ; + // recupero il riferimento di destinazione + Frame3d frDest ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest) ; + if ( ! bOk) + return GDB_ID_NULL ; + + int nSubCrvs = pCompo->GetCurveCount() ; + if ( nSubCrvToCopy > nSubCrvs - 1) + return GDB_ID_NULL ; + + // creo una copia e la porto nel frame della destinazione + const ICurve* pSubCrv = pCompo->GetCurve( nSubCrvToCopy) ; + ICurve* pSubCrvCopy = pSubCrv->Clone() ; + pSubCrvCopy->LocToLoc( frCrv, frDest) ; + int nSubCrvId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, pSubCrvCopy) ; + + return nSubCrvId ; +} + +//---------------------------------------------------------------------------- +int +ExeCopyParamRange( int nCrvId, double dUStart, double dUEnd, int nDestGrpId) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva + const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ; + // recupero il riferimento della curva + Frame3d frCrv ; + bool bOk = true ; + bOk = bOk && pGeomDB->GetGlobFrame( nCrvId, frCrv) ; + // recupero il riferimento di destinazione + Frame3d frDest ; + bOk = bOk && pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest) ; + if ( ! bOk) + return GDB_ID_NULL ; + + // creo una copia e la porto nel frame della destinazione + ICurve* pSubCrvCopy = pCrv->CopyParamRange( dUStart, dUEnd) ; + pSubCrvCopy->LocToLoc( frCrv, frDest) ; + int nSubCrvId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, pSubCrvCopy) ; + + return nSubCrvId ; } \ No newline at end of file diff --git a/LUA_GdbGetCurve.cpp b/LUA_GdbGetCurve.cpp index 1072e46..eca8813 100644 --- a/LUA_GdbGetCurve.cpp +++ b/LUA_GdbGetCurve.cpp @@ -625,6 +625,50 @@ LuaShowCurveBezierControlPoints( lua_State* L) return 2 ; } +//---------------------------------------------------------------------------- +static int +LuaCopyCompoSubCurve( lua_State* L) +{ + // 3 parametri : nCrvId, nSubCrvToCopy, nDestGrpId + int nCrvId ; + LuaCheckParam( L, 1, nCrvId) + int nSubCrvToCopy ; + LuaCheckParam( L, 2, nSubCrvToCopy) + int nDestGrpId ; + LuaCheckParam( L, 3, nDestGrpId) + LuaClearStack( L) ; + int nId = ExeCopyCompoSubCurve( nCrvId, nSubCrvToCopy, nDestGrpId) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaCopyParamRange( lua_State* L) +{ + // 4 parametri : nCrvId, dUStart, dUEnd, nDestGrpId + int nCrvId ; + LuaCheckParam( L, 1, nCrvId) + double dUStart ; + LuaCheckParam( L, 2, dUStart) + double dUEnd ; + LuaCheckParam( L, 3, dUEnd) + int nDestGrpId ; + LuaCheckParam( L, 4, nDestGrpId) + LuaClearStack( L) ; + int nId = ExeCopyParamRange( nCrvId, dUStart, dUEnd, nDestGrpId) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + //------------------------------------------------------------------------------- bool LuaInstallGdbGetCurve( LuaMgr& luaMgr) @@ -661,5 +705,7 @@ LuaInstallGdbGetCurve( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoGetTempProp", LuaCurveCompoGetTempProp) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoGetTempParam", LuaCurveCompoGetTempParam) ; bOk = bOk && luaMgr.RegisterFunction( "EgtShowCurveBezierControlPoints", LuaShowCurveBezierControlPoints) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCopyCompoSubCurve", LuaCopyCompoSubCurve) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCopyParamRange", LuaCopyParamRange) ; return bOk ; }