Files
EgtExecutor/LUA_GdbModifySurf.cpp
T
Dario Sassi 9f8be941b5 EgtExecutor 2.1i3 :
- aggiunte funzioni Exe e Lua SurfTmSwapFacets, SurfTmGetFacetBBox e SurfTmGetFacetBBoxGlob.
2019-09-30 09:22:40 +00:00

428 lines
13 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : LUA_GdbModifySurf.cpp Data : 09.03.15 Versione : 1.6b6
// Contenuto : Funzioni di modifica delle superfici per LUA.
//
//
//
// Modifiche : 09.03.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "LUA.h"
#include "/EgtDev/Include/EXeExecutor.h"
#include "/EgtDev/Include/EXeConst.h"
#include "/EgtDev/Include/EGkCurve.h"
#include "/EgtDev/Include/EGkGdbConst.h"
#include "/EgtDev/Include/EGkLuaAux.h"
using namespace std ;
//----------------------------------------------------------------------------
static int
LuaInvertSurf( lua_State* L)
{
// 1 parametro : Id/s
INTVECTOR vId ;
LuaCheckParam( L, 1, vId)
LuaClearStack( L) ;
// eseguo inversione superfici
bool bOk = ExeInvertSurface( vId) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaExplodeSurf( lua_State* L)
{
// 1 parametro : Id
int nId ;
LuaCheckParam( L, 1, nId)
LuaClearStack( L) ;
// esplosione della superficie
int nCount ;
int nFirstId = ExeExplodeSurface( nId, &nCount) ;
if ( nFirstId != GDB_ID_NULL)
LuaSetParam( L, nFirstId) ;
else
LuaSetParam( L) ;
LuaSetParam( L, nCount) ;
return 2 ;
}
//-------------------------------------------------------------------------------
static int
LuaSurfFrAdd( lua_State* L)
{
// 2 parametro : Id1, Id2
int nId1 ;
LuaCheckParam( L, 1, nId1)
int nId2 ;
LuaCheckParam( L, 2, nId2)
LuaClearStack( L) ;
// unisco alla prima regione la seconda
bool bOk = ExeSurfFrAdd( nId1, nId2) ;
LuaSetParam( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaSurfFrSubtract( lua_State* L)
{
// 2 parametro : Id1, Id2
int nId1 ;
LuaCheckParam( L, 1, nId1)
int nId2 ;
LuaCheckParam( L, 2, nId2)
LuaClearStack( L) ;
// sottraggo dalla prima regione la seconda
bool bOk = ExeSurfFrSubtract( nId1, nId2) ;
LuaSetParam( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaSurfFrIntersect( lua_State* L)
{
// 2 parametro : Id1, Id2
int nId1 ;
LuaCheckParam( L, 1, nId1)
int nId2 ;
LuaCheckParam( L, 2, nId2)
LuaClearStack( L) ;
// interseco la prima regione con la seconda
bool bOk = ExeSurfFrIntersect( nId1, nId2) ;
LuaSetParam( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaSurfFrOffset( lua_State* L)
{
// 3 parametri : Id, dDist, nType
int nId ;
LuaCheckParam( L, 1, nId)
double dDist ;
LuaCheckParam( L, 2, dDist)
int nType = ICurve::OFF_FILLET ;
LuaGetParam( L, 3, nType) ;
LuaClearStack( L) ;
// eseguo l'offset della regione
bool bOk = ExeSurfFrOffset( nId, dDist, nType) ;
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaExtractSurfFrChunkLoops( lua_State* L)
{
// 3 parametri : nId, nChunk, nDestGrpId
int nId ;
LuaCheckParam( L, 1, nId)
int nChunk ;
LuaCheckParam( L, 2, nChunk)
int nDestGrpId ;
LuaCheckParam( L, 3, nDestGrpId)
LuaClearStack( L) ;
// recupero i contorni del chunk della regione
int nCount = 0 ;
int nNewId = ExeExtractSurfFrChunkLoops( nId, nChunk, nDestGrpId, &nCount) ;
// restituisco il risultato
if ( nNewId != GDB_ID_NULL)
LuaSetParam( L, nNewId) ;
else
LuaSetParam( L) ;
LuaSetParam( L, nCount) ;
return 2 ;
}
//----------------------------------------------------------------------------
static int
LuaSurfFrMoveSimpleNoCollision( lua_State* L)
{
// 3 o 4 parametri : nId1, nId2, vtMove [, nRefType]
int nId1 ;
LuaCheckParam( L, 1, nId1)
int nId2 ;
LuaCheckParam( L, 2, nId2)
Vector3d vtMove ;
LuaCheckParam( L, 3, vtMove)
int nRefType = RTY_DEFAULT ;
LuaGetParam( L, 4, nRefType) ;
LuaClearStack( L) ;
// verifico quale è la massima traslazione possibile
double dLen = vtMove.Len() ;
Vector3d vtDir = ( dLen > EPS_SMALL ? vtMove / dLen : V_NULL) ;
bool bOk = ExeSurfFrMoveSimpleNoCollision( nId1, nId2, vtDir, dLen, nRefType) ;
// restituisco il risultato
if ( bOk)
LuaSetParam( L, dLen) ;
else
LuaSetParam( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaSurfFrRotateSimpleNoCollision( lua_State* L)
{
// 4 o 5 parametri : nId1, nId2, ptCen, dAngDeg [, nRefType]
int nId1 ;
LuaCheckParam( L, 1, nId1)
int nId2 ;
LuaCheckParam( L, 2, nId2)
Point3d ptCen ;
LuaCheckParam( L, 3, ptCen)
double dAngDeg ;
LuaCheckParam( L, 4, dAngDeg)
int nRefType = RTY_DEFAULT ;
LuaGetParam( L, 5, nRefType) ;
LuaClearStack( L) ;
// verifico quale è la massima (in valore assoluto) rotazione possibile
bool bOk = ExeSurfFrRotateSimpleNoCollision( nId1, nId2, ptCen, dAngDeg, nRefType) ;
// restituisco il risultato
if ( bOk)
LuaSetParam( L, dAngDeg) ;
else
LuaSetParam( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaExtractSurfTmLoops( lua_State* L)
{
// 2 parametri : nId, nDestGrpId
int nId ;
LuaCheckParam( L, 1, nId)
int nDestGrpId ;
LuaCheckParam( L, 2, nDestGrpId)
LuaClearStack( L) ;
// recupero i contorni della superficie
int nCount = 0 ;
int nNewId = ExeExtractSurfTmLoops( nId, nDestGrpId, &nCount) ;
// restituisco il risultato
if ( nNewId != GDB_ID_NULL)
LuaSetParam( L, nNewId) ;
else
LuaSetParam( L) ;
LuaSetParam( L, nCount) ;
return 2 ;
}
//----------------------------------------------------------------------------
static int
LuaGetSurfTmSilhouette( lua_State* L)
{
// 3 o 4 parametri : nId, vtDir, nDestGrpId [, nRefType]
int nId ;
LuaCheckParam( L, 1, nId)
Vector3d vtDir ;
LuaCheckParam( L, 2, vtDir)
int nDestGrpId ;
LuaCheckParam( L, 3, nDestGrpId)
int nRefType = RTY_DEFAULT ;
LuaGetParam( L, 4, nRefType) ;
LuaClearStack( L) ;
// recupero i contorni della superficie
int nCount = 0 ;
int nNewId = ExeGetSurfTmSilhouette( nId, vtDir, nDestGrpId, nRefType, &nCount) ;
// restituisco il risultato
if ( nNewId != GDB_ID_NULL)
LuaSetParam( L, nNewId) ;
else
LuaSetParam( L) ;
LuaSetParam( L, nCount) ;
return 2 ;
}
//----------------------------------------------------------------------------
static int
LuaExtractSurfTmFacetLoops( lua_State* L)
{
// 3 parametri : nId, nFacet, nDestGrpId
int nId ;
LuaCheckParam( L, 1, nId)
int nFacet ;
LuaCheckParam( L, 2, nFacet)
int nDestGrpId ;
LuaCheckParam( L, 3, nDestGrpId)
LuaClearStack( L) ;
// recupero i contorni della faccetta della superficie
int nCount ;
int nNewId = ExeExtractSurfTmFacetLoops( nId, nFacet, nDestGrpId, &nCount) ;
// restituisco il risultato
if ( nNewId != GDB_ID_NULL)
LuaSetParam( L, nNewId) ;
else
LuaSetParam( L) ;
LuaSetParam( L, nCount) ;
return 2 ;
}
//----------------------------------------------------------------------------
static int
LuaCopySurfTmFacet( lua_State* L)
{
// 3 parametri : nId, nFacet, nDestGrpId
int nId ;
LuaCheckParam( L, 1, nId)
int nFacet ;
LuaCheckParam( L, 2, nFacet)
int nDestGrpId ;
LuaCheckParam( L, 3, nDestGrpId)
LuaClearStack( L) ;
// copio la faccia della superficie nel gruppo indicato
int nNewId = ExeCopySurfTmFacet( nId, nFacet, nDestGrpId) ;
// restituisco il risultato
if ( nNewId != GDB_ID_NULL)
LuaSetParam( L, nNewId) ;
else
LuaSetParam( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaSurfTmSwapFacets( lua_State* L)
{
// 3 parametri : nId, nFacet1, nFacet2
int nId ;
LuaCheckParam( L, 1, nId)
int nFacet1 ;
LuaCheckParam( L, 2, nFacet1)
int nFacet2 ;
LuaCheckParam( L, 3, nFacet2)
LuaClearStack( L) ;
// eseguo scambio facce della superficie
bool bOk = ExeSurfTmSwapFacets( nId, nFacet1, nFacet2) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaSurfTmGetFacetBBox( lua_State* L)
{
// 3 parametri : nId, nFacet, nFlag
int nId ;
LuaCheckParam( L, 1, nId)
int nFacet ;
LuaCheckParam( L, 2, nFacet)
int nFlag ;
LuaCheckParam( L, 3, nFlag)
LuaClearStack( L) ;
// recupero il bounding box della faccia in locale
BBox3d b3Box ;
bool bOk = ExeSurfTmGetFacetBBox( nId, nFacet, nFlag, b3Box) ;
// restituisco il risultato
if ( bOk)
LuaSetParam( L, b3Box) ;
else
LuaSetParam( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaSurfTmGetFacetBBoxGlob( lua_State* L)
{
// 3 parametri : nId, nFacet, nFlag
int nId ;
LuaCheckParam( L, 1, nId)
int nFacet ;
LuaCheckParam( L, 2, nFacet)
int nFlag ;
LuaCheckParam( L, 3, nFlag)
LuaClearStack( L) ;
// recupero il bounding box della faccia in locale
BBox3d b3Box ;
bool bOk = ExeSurfTmGetFacetBBoxGlob( nId, nFacet, nFlag, b3Box) ;
// restituisco il risultato
if ( bOk)
LuaSetParam( L, b3Box) ;
else
LuaSetParam( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaCutSurfTmPlane( lua_State* L)
{
// 4 o 5 parametri : Id, ptOn, vtN, bSaveOnEq [, nRefType]
int nId ;
LuaCheckParam( L, 1, nId)
Point3d ptOn ;
LuaCheckParam( L, 2, ptOn)
Vector3d vtN ;
LuaCheckParam( L, 3, vtN)
bool bSaveOnEq ;
LuaGetParam( L, 4, bSaveOnEq) ;
int nRefType = RTY_DEFAULT ;
LuaGetParam( L, 5, nRefType) ;
LuaClearStack( L) ;
// taglio la superficie con ilpiano
bool bOk = ExeCutSurfTmPlane( nId, ptOn, vtN, bSaveOnEq, nRefType) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaCutSurfTmClosedCurve( lua_State* L)
{
// 3 parametri : SurfId, CurveId, bSaveOnEq
int nSurfId ;
LuaCheckParam( L, 1, nSurfId)
int nCurveId ;
LuaCheckParam( L, 2, nCurveId)
bool bSaveOnEq ;
LuaGetParam( L, 3, bSaveOnEq) ;
LuaClearStack( L) ;
// taglio la superficie con ilpiano
bool bOk = ExeCutSurfTmClosedCurve( nSurfId, nCurveId, bSaveOnEq) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
bool
LuaInstallGdbModifySurf( LuaMgr& luaMgr)
{
bool bOk = ( &luaMgr != nullptr) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtInvertSurf", LuaInvertSurf) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtExplodeSurf", LuaExplodeSurf) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrAdd", LuaSurfFrAdd) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrSubtract", LuaSurfFrSubtract) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrIntersect", LuaSurfFrIntersect) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrOffset", LuaSurfFrOffset) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtExtractSurfFrChunkLoops", LuaExtractSurfFrChunkLoops) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrMoveSimpleNoCollision", LuaSurfFrMoveSimpleNoCollision) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrRotateSimpleNoCollision", LuaSurfFrRotateSimpleNoCollision) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtExtractSurfTmLoops", LuaExtractSurfTmLoops) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtGetSurfTmSilhouette", LuaGetSurfTmSilhouette) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtExtractSurfTmFacetLoops", LuaExtractSurfTmFacetLoops) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtCopySurfTmFacet", LuaCopySurfTmFacet) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmSwapFacets", LuaSurfTmSwapFacets) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetFacetBBox", LuaSurfTmGetFacetBBox) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetFacetBBoxGlob", LuaSurfTmGetFacetBBoxGlob) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtCutSurfTmPlane", LuaCutSurfTmPlane) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtCutSurfTmClosedCurve", LuaCutSurfTmClosedCurve) ;
return bOk ;
}