eacbbc1c1f
- aggiunte funzioni Exe e Lua GetSurfTmPlaneInters.
373 lines
11 KiB
C++
373 lines
11 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) ;
|
|
// recupero i contorni della faccetta della superficie
|
|
int nNewId = ExeCopySurfTmFacet( nId, nFacet, nDestGrpId) ;
|
|
// restituisco il risultato
|
|
if ( nNewId != GDB_ID_NULL)
|
|
LuaSetParam( L, nNewId) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaGetSurfTmPlaneInters( lua_State* L)
|
|
{
|
|
// 4 o 5 parametri : Id, ptOn, vtN, nDestGrpId [, nRefType]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
Point3d ptOn ;
|
|
LuaCheckParam( L, 2, ptOn)
|
|
Vector3d vtN ;
|
|
LuaCheckParam( L, 3, vtN)
|
|
int nDestGrpId ;
|
|
LuaGetParam( L, 4, nDestGrpId) ;
|
|
int nRefType = RTY_DEFAULT ;
|
|
LuaGetParam( L, 5, nRefType) ;
|
|
LuaClearStack( L) ;
|
|
// eseguo l'intersezione
|
|
int nPntCount = 0 ;
|
|
int nCrvCount = 0 ;
|
|
int nSrfCount = 0 ;
|
|
int nNewId = ExeGetSurfTmPlaneInters( nId, ptOn, vtN, nDestGrpId, nRefType, &nPntCount, &nCrvCount, &nSrfCount) ;
|
|
// restituisco il risultato
|
|
if ( nNewId != GDB_ID_NULL)
|
|
LuaSetParam( L, nNewId) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L, nPntCount) ;
|
|
LuaSetParam( L, nCrvCount) ;
|
|
LuaSetParam( L, nSrfCount) ;
|
|
return 4 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCutSurfTm( 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
|
|
bool bOk = ExeCutSurfTm( nId, ptOn, vtN, bSaveOnEq, nRefType) ;
|
|
// 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( "EgtGetSurfTmPlaneInters", LuaGetSurfTmPlaneInters) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCutSurfTm", LuaCutSurfTm) ;
|
|
return bOk ;
|
|
}
|