diff --git a/EXE_GdbCreateSurf.cpp b/EXE_GdbCreateSurf.cpp index 0e174d3..1943cb1 100644 --- a/EXE_GdbCreateSurf.cpp +++ b/EXE_GdbCreateSurf.cpp @@ -747,9 +747,9 @@ ExeCreateSurfTmPyramid( int nParentId, const Point3d& ptIni, const Point3d& ptCr // creo la piramide nel suo riferimento intrinseco PtrOwner pSTM( GetSurfTriMeshPyramid( abs( dWidth), dLen, dHeight)) ; bOk = bOk && ! IsNull( pSTM) ; - // eventuale traslazione per larghezza negativa - if ( bOk && dWidth < 0) - pSTM->Translate( Vector3d( dWidth, 0, 0)) ; + // traslazione per riferimento BL e anche per eventuale larghezza negativa + if ( bOk) + pSTM->Translate( Vector3d( dWidth / 2 + min( dWidth, 0.), dLen / 2, 0)) ; // porto la piramide nel riferimento locale bOk = bOk && pSTM->ToGlob( frBox) ; // inserisco la superficie nel DB @@ -890,6 +890,63 @@ ExeCreateSurfTmSphere( int nParentId, const Point3d& ptOrig, return nNewId ; } +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmPyramidFrustum( int nParentId, double dBaseDimX, double dBaseDimY, double dTopDimX, double dTopDimY, double dHeight) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + nParentId = AdjustId( nParentId) ; + bool bOk = true ; + // creo il tronco di cono + PtrOwner pSTM( GetSurfTriMeshPyramidFrustum( dBaseDimX, dBaseDimY, dTopDimX, dTopDimY, dHeight)) ; + bOk = bOk && ! IsNull( pSTM) ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSTM)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmPyramidFrustum(" + IdToString( nParentId) + "," + + ToString( dBaseDimX) + "," + + ToString( dBaseDimY) + "," + + ToString( dTopDimX) + "," + + ToString( dTopDimY) + "," + + ToString( dHeight) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmConeFrustum( int nParentId, double dBaseRad, double dTopRad, double dHeight, double dLinTol) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + nParentId = AdjustId( nParentId) ; + bool bOk = true ; + // creo il tronco di cono + PtrOwner pSTM( GetSurfTriMeshConeFrustum( dBaseRad, dTopRad, dHeight, dLinTol)) ; + bOk = bOk && ! IsNull( pSTM) ; + // inserisco la superficie nel DB + int nNewId = ( bOk ? pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSTM)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmConeFrustum(" + IdToString( nParentId) + "," + + ToString( dBaseRad) + "," + + ToString( dTopRad) + "," + + ToString( dHeight) + "," + + ToString( dLinTol) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + //------------------------------------------------------------------------------- int ExeCreateSurfTmTriangle( int nParentId, const Point3d& ptP1, const Point3d& ptP2, const Point3d& ptP3, int nRefType) @@ -1478,10 +1535,15 @@ ExeCreateSurfTmRuled( int nParentId, int nPtOrCrvId1, int nPtOrCrvId2, int nType ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { + string sType = "'IP'" ; + if ( nType == ISurfTriMesh::RLT_MINDIST) + sType = "'MD'" ; + else if ( nType == ISurfTriMesh::RLT_ISOPAR_SMOOTH) + sType = "'IP_SM'" ; string sLua = "EgtSurfTmRuled(" + IdToString( nParentId) + "," + ToString( nPtOrCrvId1) + "," + ToString( nPtOrCrvId2) + "," + - ( nType == ISurfTriMesh::RLT_MINDIST ? "'MD'" : "'IP'") + "," + + sType + "," + ToString( dLinTol) + ")" + " -- Id=" + ToString( nNewId) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; diff --git a/EXE_GdbGetCurve.cpp b/EXE_GdbGetCurve.cpp index 46c3bf5..9786754 100644 --- a/EXE_GdbGetCurve.cpp +++ b/EXE_GdbGetCurve.cpp @@ -16,6 +16,7 @@ #include "EXE.h" #include "EXE_Const.h" #include "EXE_Macro.h" +#include "AuxTools.h" #include "GeoTools.h" #include "/EgtDev/Include/EgtNumUtils.h" #include "/EgtDev/Include/EXeExecutor.h" @@ -31,6 +32,8 @@ #include "/EgtDev/Include/EGkIntersCurves.h" #include "/EgtDev/Include/EGkSurfFlatRegion.h" +using namespace std ; + //---------------------------------------------------------------------------- bool ExeCurveDomain( int nId, double* pdStart, double* pdEnd) @@ -755,15 +758,15 @@ ExeShowCurveBezierControlPoints( int nCrvId, int nDestGrpId, int* pnCount) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) - // recupero la curva di bezier + // recupero la curva di Bezier IGeoObj* pGeoObj = pGeomDB->GetGeoObj( nCrvId) ; if ( pGeoObj->GetType() != CRV_BEZIER && pGeoObj->GetType() != CRV_COMPO) return GDB_ID_NULL ; - // recupero il riferimento della curva + // recupero il riferimento della curva Frame3d frCrv ; bool bOk = true ; bOk = bOk && pGeomDB->GetGlobFrame( nCrvId, frCrv) ; - // recupero il riferimento di destinazione + // recupero il riferimento di destinazione Frame3d frDest ; bOk = bOk && pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest) ; if ( ! bOk) @@ -799,7 +802,7 @@ ExeShowCurveBezierControlPoints( int nCrvId, int nDestGrpId, int* pnCount) ++nCount ; } } - // restituisco i risultati + // restituisco i risultati if ( pnCount != nullptr) *pnCount = nCount ; return nFirstId ; @@ -826,7 +829,7 @@ ExeShowCurveBezierControlPoints( int nCrvId, int nDestGrpId, int* pnCount) if ( nId != GDB_ID_NULL) ++nCount ; } - // restituisco i risultati + // restituisco i risultati if ( pnCount != nullptr) *pnCount = nCount ; return nFirstId ; @@ -841,11 +844,13 @@ ExeCurveMaxOffset( int nId, double& dMaxOffset) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) - // verifico il parametro + // verifico il parametro if ( &dMaxOffset == nullptr) return false ; - // recupero la curva + // recupero la curva const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nId)) ; + if ( pCrv == nullptr) + return false ; return CalcCurveLimitOffset( *pCrv, dMaxOffset) ; } @@ -855,15 +860,15 @@ ExeCopyCompoSubCurve( int nCrvId, int nSubCrvToCopy, int nDestGrpId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) - // recupero la curva compo + // recupero la curva compo const ICurveComposite* pCompo = GetCurveComposite( pGeomDB->GetGeoObj( nCrvId)) ; if ( pCompo == nullptr) return GDB_ID_NULL ; - // recupero il riferimento della curva + // recupero il riferimento della curva Frame3d frCrv ; bool bOk = true ; bOk = bOk && pGeomDB->GetGlobFrame( nCrvId, frCrv) ; - // recupero il riferimento di destinazione + // recupero il riferimento di destinazione Frame3d frDest ; bOk = bOk && pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest) ; if ( ! bOk) @@ -873,12 +878,23 @@ ExeCopyCompoSubCurve( int nCrvId, int nSubCrvToCopy, int nDestGrpId) if ( nSubCrvToCopy > nSubCrvs - 1) return GDB_ID_NULL ; - // creo una copia e la porto nel frame della destinazione + // creo una copia e la porto nel frame della destinazione const ICurve* pSubCrv = pCompo->GetCurve( nSubCrvToCopy) ; ICurve* pSubCrvCopy = pSubCrv->Clone() ; + if ( pSubCrvCopy == nullptr) + return GDB_ID_NULL ; pSubCrvCopy->LocToLoc( frCrv, frDest) ; int nSubCrvId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, pSubCrvCopy) ; - + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtCopyCompoSubCurve(" + IdToString( nCrvId) + "," + + ToString( nSubCrvToCopy) + "," + + IdToString( nDestGrpId) + ")" + + " -- Id=" + ToString( nSubCrvId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità return nSubCrvId ; } @@ -888,22 +904,25 @@ ExeCopyParamRange( int nCrvId, double dUStart, double dUEnd, int nDestGrpId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) - // recupero la curva + // recupero la curva const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ; - // recupero il riferimento della curva + // recupero il riferimento della curva Frame3d frCrv ; bool bOk = true ; bOk = bOk && pGeomDB->GetGlobFrame( nCrvId, frCrv) ; - // recupero il riferimento di destinazione + // 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 + // creo una copia e la porto nel frame della destinazione ICurve* pSubCrvCopy = pCrv->CopyParamRange( dUStart, dUEnd) ; + if ( pSubCrvCopy == nullptr) + return GDB_ID_NULL ; pSubCrvCopy->LocToLoc( frCrv, frDest) ; int nSubCrvId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, pSubCrvCopy) ; + ExeSetModified() ; return nSubCrvId ; } \ No newline at end of file diff --git a/LUA_GdbCreateSurf.cpp b/LUA_GdbCreateSurf.cpp index 69e8c41..14d2542 100644 --- a/LUA_GdbCreateSurf.cpp +++ b/LUA_GdbCreateSurf.cpp @@ -417,6 +417,60 @@ LuaCreateSurfTmSphere( lua_State* L) return 1 ; } +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmPyramidFrustum( lua_State* L) +{ + // 6 parametri : ParentId, dBaseDimX, dBaseDimY, dTopDimX, dTopDimY, dHeight + int nParentId ; + LuaCheckParam( L, 1, nParentId) + double dBaseDimX ; + LuaCheckParam( L, 2, dBaseDimX) + double dBaseDimY ; + LuaCheckParam( L, 3, dBaseDimY) + double dTopDimX ; + LuaCheckParam( L, 4, dTopDimX) + double dTopDimY ; + LuaCheckParam( L, 5, dTopDimY) + double dHeight ; + LuaCheckParam( L, 6, dHeight) + LuaClearStack( L) ; + // creo STM cilindro + int nId = ExeCreateSurfTmPyramidFrustum( nParentId, dBaseDimX, dBaseDimY, dTopDimX, dTopDimY, dHeight) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmConeFrustum( lua_State* L) +{ + // 4 o 5 parametri : ParentId, dBaseRad, dTopRad, dHeight [, dTol] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + double dBaseRad ; + LuaCheckParam( L, 2, dBaseRad) + double dTopRad ; + LuaCheckParam( L, 3, dTopRad) + double dHeight ; + LuaCheckParam( L, 4, dHeight) + double dLinTol = LIN_TOL_SRF ; + LuaGetParam( L, 5, dLinTol) ; + LuaClearStack( L) ; + // creo STM cilindro + int nId = ExeCreateSurfTmConeFrustum( nParentId, dBaseRad, dTopRad, dHeight, dLinTol) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + //------------------------------------------------------------------------------- static int LuaCreateSurfTmTriangle( lua_State* L) @@ -1317,6 +1371,8 @@ LuaInstallGdbCreateSurf( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmCylinder", LuaCreateSurfTmCylinder) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmCone", LuaCreateSurfTmCone) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmSphere", LuaCreateSurfTmSphere) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmPyramidFrustum", LuaCreateSurfTmPyramidFrustum) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmConeFrustum", LuaCreateSurfTmConeFrustum) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmTriangle", LuaCreateSurfTmTriangle) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmRectangle", LuaCreateSurfTmRectangle) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmByFlatContour", LuaCreateSurfTmByFlatContour) ;