From 2794f358050b31daade96043ec20bdc6b7a11569 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 18 Sep 2023 08:14:36 +0200 Subject: [PATCH] EgtExecutor : - aggiunte funzioni Exe e Lua CreateSurfTmTriangle e CreateSurfTmRectangle - in Copy, CopyGlob, Relocate e RelocateGlob RefId ora accetta anche valori simbolici (layer corrente, ..). --- EXE_GdbCreateSurf.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++- EXE_GdbObjects.cpp | 21 ++++++---- LUA_GdbCreateSurf.cpp | 56 +++++++++++++++++++++++++- 3 files changed, 160 insertions(+), 11 deletions(-) diff --git a/EXE_GdbCreateSurf.cpp b/EXE_GdbCreateSurf.cpp index 0f0e215..07da47d 100644 --- a/EXE_GdbCreateSurf.cpp +++ b/EXE_GdbCreateSurf.cpp @@ -56,8 +56,7 @@ ExeCreateSurfFrRectangle( int nParentId, const Point3d& ptIni, const Point3d& pt if ( ( frEnt.VersZ() * vtZL) < 0) frEnt.PseudoMirror( frEnt.Orig(), frEnt.VersZ()) ; // ricavo le dimensioni della base - Point3d ptCrossI = ptCrossL ; - ptCrossI.ToLoc( frEnt) ; + Point3d ptCrossI = GetToLoc( ptCrossL, frEnt) ; double dWidth = ptCrossI.x ; double dLen = ptCrossI.y ; // creo il rettangolo nel suo riferimento intrinseco @@ -863,6 +862,97 @@ ExeCreateSurfTmSphere( int nParentId, const Point3d& ptOrig, return nNewId ; } +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmTriangle( int nParentId, const Point3d& ptP1, const Point3d& ptP2, const Point3d& ptP3, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + nParentId = AdjustId( nParentId) ; + // recupero il riferimento locale + Frame3d frLoc ; + bool bOk = pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale i punti + Point3d ptP1L = GetPointLocal( pGeomDB, ptP1, nRefType, frLoc) ; + Point3d ptP2L = GetPointLocal( pGeomDB, ptP2, nRefType, frLoc) ; + Point3d ptP3L = GetPointLocal( pGeomDB, ptP3, nRefType, frLoc) ; + // creo la superficie trimesh + PtrOwner pStm( CreateSurfTriMesh()) ; + bOk = bOk && ! IsNull( pStm) ; + // assegno il triangolo + if ( bOk) { + pStm->Init( 3, 1, 1) ; + int vV[3]{ pStm->AddVertex( ptP1L), + pStm->AddVertex( ptP2L), + pStm->AddVertex( ptP3L)} ; + bOk = ( pStm->AddTriangle( vV) != SVT_NULL) && pStm->AdjustTopology() ; + } + // 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 = "EgtSurfTmTriangle(" + IdToString( nParentId) + ",{" + + ToString( ptP1) + "},{" + + ToString( ptP2) + "},{" + + ToString( ptP3) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + +//------------------------------------------------------------------------------- +int +ExeCreateSurfTmRectangle( int nParentId, const Point3d& ptO, const Point3d& ptL, const Point3d& ptT, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + nParentId = AdjustId( nParentId) ; + // recupero il riferimento locale + Frame3d frLoc ; + bool bOk = pGeomDB->GetGroupGlobFrame( nParentId, frLoc) ; + // porto in locale i punti + Point3d ptOL = GetPointLocal( pGeomDB, ptO, nRefType, frLoc) ; + Point3d ptLL = GetPointLocal( pGeomDB, ptL, nRefType, frLoc) ; + Point3d ptTL = GetPointLocal( pGeomDB, ptT, nRefType, frLoc) ; + // modifico il punto trasversale per metterlo perpendicolare al lato Lungo + ptTL -= ParallCompo( ptTL - ptOL, ptLL - ptOL) ; + // calcolo il quarto punto + Point3d ptVL = ptTL + ( ptLL - ptOL) ; + // creo la superficie trimesh + PtrOwner pStm( CreateSurfTriMesh()) ; + bOk = bOk && ! IsNull( pStm) ; + // assegno il triangolo + if ( bOk) { + pStm->Init( 4, 2, 1) ; + int vV[4]{ pStm->AddVertex( ptOL), + pStm->AddVertex( ptLL), + pStm->AddVertex( ptTL), + pStm->AddVertex( ptVL)} ; + int vV1[3]{ vV[0], vV[1], vV[2] } ; + int vV2[3]{ vV[2], vV[1], vV[3] } ; + bOk = ( pStm->AddTriangle( vV1) != SVT_NULL) && ( pStm->AddTriangle( vV2) != SVT_NULL) && pStm->AdjustTopology() ; + } + // 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 = "EgtSurfTmRectangle(" + IdToString( nParentId) + ",{" + + ToString( ptO) + "},{" + + ToString( ptL) + "},{" + + ToString( ptT) + "}," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + //------------------------------------------------------------------------------- int ExeCreateSurfTmByFlatContour( int nParentId, int nCrvId, double dLinTol) diff --git a/EXE_GdbObjects.cpp b/EXE_GdbObjects.cpp index b5a2f9b..63a8872 100644 --- a/EXE_GdbObjects.cpp +++ b/EXE_GdbObjects.cpp @@ -15,6 +15,7 @@ #include "stdafx.h" #include "EXE.h" #include "EXE_Macro.h" +#include "GeoTools.h" #include "AuxTools.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EGkStringUtils3d.h" @@ -254,6 +255,7 @@ ExeCopy( int nSouId, int nRefId, int nSonBeforeAfter) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + nRefId = AdjustId( nRefId) ; // eseguo la copia int nNewId = pGeomDB->Copy( nSouId, GDB_ID_NULL, nRefId, nSonBeforeAfter) ; pGeomDB->RemoveInfo( nNewId, GDB_SI_LIST) ; @@ -264,11 +266,11 @@ ExeCopy( int nSouId, int nRefId, int nSonBeforeAfter) string sLua ; if ( nSonBeforeAfter == GDB_LAST_SON) sLua = "EgtCopy(" + ToString( nSouId) + "," + - ToString( nRefId) + ")" + + IdToString( nRefId) + ")" + " -- Id=" + ToString( nNewId) ; else sLua = "EgtCopy(" + ToString( nSouId) + "," + - ToString( nRefId) + "," + + IdToString( nRefId) + "," + InsToString( nSonBeforeAfter) + ")" + " -- Id=" + ToString( nNewId) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -283,6 +285,7 @@ ExeCopyGlob( int nSouId, int nRefId, int nSonBeforeAfter) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + nRefId = AdjustId( nRefId) ; // eseguo la copia mantenendo la posizione in globale int nNewId = pGeomDB->CopyGlob( nSouId, GDB_ID_NULL, nRefId, nSonBeforeAfter) ; pGeomDB->RemoveInfo( nNewId, GDB_SI_LIST) ; @@ -293,11 +296,11 @@ ExeCopyGlob( int nSouId, int nRefId, int nSonBeforeAfter) string sLua ; if ( nSonBeforeAfter == GDB_LAST_SON) sLua = "EgtCopyGlob(" + ToString( nSouId) + "," + - ToString( nRefId) + ")" + + IdToString( nRefId) + ")" + " -- Id=" + ToString( nNewId) ; else sLua = "EgtCopyGlob(" + ToString( nSouId) + "," + - ToString( nRefId) + "," + + IdToString( nRefId) + "," + InsToString( nSonBeforeAfter) + ")" + " -- Id=" + ToString( nNewId) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -312,6 +315,7 @@ ExeRelocate( int nSouId, int nRefId, int nSonBeforeAfter) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) + nRefId = AdjustId( nRefId) ; // eseguo la rilocazione bool bOk = pGeomDB->Relocate( nSouId, nRefId, nSonBeforeAfter) ; ExeSetModified() ; @@ -320,11 +324,11 @@ ExeRelocate( int nSouId, int nRefId, int nSonBeforeAfter) string sLua ; if ( nSonBeforeAfter == GDB_LAST_SON) sLua = "EgtRelocate(" + ToString( nSouId) + "," + - ToString( nRefId) + ")" + + IdToString( nRefId) + ")" + " -- Ok=" + ToString( bOk) ; else sLua = "EgtRelocate(" + ToString( nSouId) + "," + - ToString( nRefId) + "," + + IdToString( nRefId) + "," + InsToString( nSonBeforeAfter) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; @@ -339,6 +343,7 @@ ExeRelocateGlob( int nSouId, int nRefId, int nSonBeforeAfter) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) + nRefId = AdjustId( nRefId) ; // eseguo la rilocazione mantenendo la posizione in globale bool bOk = pGeomDB->RelocateGlob( nSouId, nRefId, nSonBeforeAfter) ; ExeSetModified() ; @@ -347,11 +352,11 @@ ExeRelocateGlob( int nSouId, int nRefId, int nSonBeforeAfter) string sLua ; if ( nSonBeforeAfter == GDB_LAST_SON) sLua = "EgtRelocateGlob(" + ToString( nSouId) + "," + - ToString( nRefId) + ")" + + IdToString( nRefId) + ")" + " -- Ok=" + ToString( bOk) ; else sLua = "EgtRelocateGlob(" + ToString( nSouId) + "," + - ToString( nRefId) + "," + + IdToString( nRefId) + "," + InsToString( nSonBeforeAfter) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; diff --git a/LUA_GdbCreateSurf.cpp b/LUA_GdbCreateSurf.cpp index a449004..f03efd0 100644 --- a/LUA_GdbCreateSurf.cpp +++ b/LUA_GdbCreateSurf.cpp @@ -385,7 +385,7 @@ LuaCreateSurfTmSphere( lua_State* L) else LuaGetParam( L, 4, nRefType) ; LuaClearStack( L) ; - // creo STM cilindro + // creo STM sfera int nId = ExeCreateSurfTmSphere( nParentId, ptOrig, dRad, dLinTol, nRefType) ; // restituisco il risultato if ( nId != GDB_ID_NULL) @@ -395,6 +395,58 @@ LuaCreateSurfTmSphere( lua_State* L) return 1 ; } +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmTriangle( lua_State* L) +{ + // 4 o 5 parametri : ParentId, PtP1, PtP2, PtP3 [, nRefType] + 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 ; + LuaGetParam( L, 5, nRefType) ; + LuaClearStack( L) ; + // creo STM triangolo + int nId = ExeCreateSurfTmTriangle( nParentId, PtP1, PtP2, PtP3, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaCreateSurfTmRectangle( lua_State* L) +{ + // 4 o 5 parametri : ParentId, PtO, PtL, PtT [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + Point3d ptO ; + LuaCheckParam( L, 2, ptO) + Point3d ptL ; + LuaCheckParam( L, 3, ptL) + Point3d ptT ; + LuaCheckParam( L, 4, ptT) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 5, nRefType) ; + LuaClearStack( L) ; + // creo STM rettangolo + int nId = ExeCreateSurfTmRectangle( nParentId, ptO, ptL, ptT, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + //------------------------------------------------------------------------------- static int LuaCreateSurfTmByFlatContour( lua_State* L) @@ -835,6 +887,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( "EgtSurfTmTriangle", LuaCreateSurfTmTriangle) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmRectangle", LuaCreateSurfTmRectangle) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmByFlatContour", LuaCreateSurfTmByFlatContour) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmByRegion", LuaCreateSurfTmByRegion) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmByExtrusion", LuaCreateSurfTmByExtrusion) ;