cd3db614dd
- aggiustamenti per modifiche a Plane3d.
966 lines
27 KiB
C++
966 lines
27 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : LUA_GeoSnap.cpp Data : 02.10.14 Versione : 1.5i5
|
|
// Contenuto : Funzioni di snap ad oggetti del DB geometrico per LUA.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 02.10.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LUA.h"
|
|
#include "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EGkLuaAux.h"
|
|
|
|
using namespace std ;
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaStartPoint( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il punto iniziale dell'entità
|
|
Point3d ptP ;
|
|
if ( ExeStartPoint( nId, nRefId, ptP))
|
|
LuaSetParam( L, ptP) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaEndPoint( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il punto finale dell'entità
|
|
Point3d ptP ;
|
|
if ( ExeEndPoint( nId, nRefId, ptP))
|
|
LuaSetParam( L, ptP) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaMidPoint( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il punto centrale dell'entità
|
|
Point3d ptP ;
|
|
if ( ExeMidPoint( nId, nRefId, ptP))
|
|
LuaSetParam( L, ptP) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCenterPoint( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il punto centrale dell'entità
|
|
Point3d ptP ;
|
|
if ( ExeCenterPoint( nId, nRefId, ptP))
|
|
LuaSetParam( L, ptP) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCentroid( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il centro geometrico dell'entità
|
|
Point3d ptP ;
|
|
if ( ExeCentroid( nId, nRefId, ptP))
|
|
LuaSetParam( L, ptP) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaAtParamPoint( lua_State* L)
|
|
{
|
|
// 2 o 3 parametri : Id, U [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
double dU ;
|
|
LuaCheckParam( L, 2, dU)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 3, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il punto in posizione parametrica U della curva
|
|
Point3d ptP ;
|
|
if ( ExeAtParamPoint( nId, dU, nRefId, ptP))
|
|
LuaSetParam( L, ptP) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaNearPoint( lua_State* L)
|
|
{
|
|
// 2 o 3 parametri : Id, ptNear [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
Point3d ptNear ;
|
|
LuaCheckParam( L, 2, ptNear)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 3, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il punto di intersezione tra le curve più vicino al punto passato
|
|
Point3d ptP ;
|
|
if ( ExeNearPoint( nId, ptNear, nRefId, ptP))
|
|
LuaSetParam( L, ptP) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaIntersectionPoint( lua_State* L)
|
|
{
|
|
// 3 o 4 parametri : Id1, Id2, ptNear [, nRefId]
|
|
int nId1 ;
|
|
LuaCheckParam( L, 1, nId1)
|
|
int nId2 ;
|
|
LuaCheckParam( L, 2, nId2)
|
|
Point3d ptNear ;
|
|
LuaCheckParam( L, 3, ptNear)
|
|
int nRefId = nId1 ;
|
|
LuaGetParam( L, 4, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il punto di intersezione tra le curve più vicino al punto passato
|
|
Point3d ptP ;
|
|
if ( ExeIntersectionPoint( nId1, nId2, ptNear, nRefId, ptP))
|
|
LuaSetParam( L, ptP) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaStartVector( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il vettore tangente all'inizio della curva
|
|
Vector3d vtV ;
|
|
if ( ExeStartVector( nId, nRefId, vtV))
|
|
LuaSetParam( L, vtV) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaEndVector( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il vettore tangente alla fine della curva
|
|
Vector3d vtV ;
|
|
if ( ExeEndVector( nId, nRefId, vtV))
|
|
LuaSetParam( L, vtV) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaMidVector( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il vettore tangente nel punto medio della curva
|
|
Vector3d vtV ;
|
|
if ( ExeMidVector( nId, nRefId, vtV))
|
|
LuaSetParam( L, vtV) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaAtParamVector( lua_State* L)
|
|
{
|
|
// 2, 3 o 4 parametri : Id, U, nSide [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
double dU ;
|
|
LuaCheckParam( L, 2, dU)
|
|
int nSide ;
|
|
LuaCheckParam( L, 3, nSide) ;
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 4, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il punto in posizione parametrica U della curva
|
|
Vector3d vtV ;
|
|
if ( ExeAtParamVector( nId, dU, nSide, nRefId, vtV))
|
|
LuaSetParam( L, vtV) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaFrame( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il frame
|
|
Frame3d frFrame ;
|
|
if ( ExeFrame( nId, nRefId, frFrame))
|
|
LuaSetParam( L, frFrame) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCurveDomain( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero il dominio della curva
|
|
double dStart, dEnd ;
|
|
if ( ExeCurveDomain( nId, &dStart, &dEnd)) {
|
|
LuaSetParam( L, dStart) ;
|
|
LuaSetParam( L, dEnd) ;
|
|
return 2 ;
|
|
}
|
|
else {
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCurveLength( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero la lunghezza della curva
|
|
double dLen ;
|
|
if ( ExeCurveLength( nId, &dLen))
|
|
LuaSetParam( L, dLen) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCurveIsClosed( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// verifico se curva chiusa
|
|
bool bClosed = ExeCurveIsClosed( nId) ;
|
|
LuaSetParam( L, bClosed) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCurveIsFlat( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// verifico se curva piatta e restituisco il piano medio
|
|
Plane3d Plane ;
|
|
bool bFlat = ExeCurveIsFlat( nId, Plane) ;
|
|
LuaSetParam( L, bFlat) ;
|
|
LuaSetParam( L, Plane.GetVersN()) ;
|
|
LuaSetParam( L, Plane.GetDist()) ;
|
|
return 3 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCurveAreaXY( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero l'area della curva proiettata sul piano XY
|
|
double dArea ;
|
|
if ( ExeCurveAreaXY( nId, dArea))
|
|
LuaSetParam( L, dArea) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCurveArea( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero il piano medio della curva e la sua area su di esso
|
|
Plane3d Plane ;
|
|
double dArea ;
|
|
if ( ExeCurveArea( nId, Plane, dArea)) {
|
|
LuaSetParam( L, Plane.GetVersN()) ;
|
|
LuaSetParam( L, Plane.GetDist()) ;
|
|
LuaSetParam( L, dArea) ;
|
|
return 3 ;
|
|
}
|
|
else {
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCurveExtrusion( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il versore
|
|
Vector3d vtExtr ;
|
|
if ( ExeCurveExtrusion( nId, nRefId, vtExtr))
|
|
LuaSetParam( L, vtExtr) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCurveThickness( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero lo spessore
|
|
double dThick ;
|
|
if ( ExeCurveThickness( nId, &dThick))
|
|
LuaSetParam( L, dThick) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaExtrusionByThickness( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il versore e lo spessore
|
|
Vector3d vtExtr ;
|
|
double dThick ;
|
|
if ( ExeCurveExtrusion( nId, nRefId, vtExtr) && ! vtExtr.IsSmall() &&
|
|
ExeCurveThickness( nId, &dThick) && fabs( dThick) > EPS_SMALL)
|
|
vtExtr *= dThick ;
|
|
else
|
|
vtExtr = V_NULL ;
|
|
LuaSetParam( L, vtExtr) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCurveSelfIntersCount( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero il numero di auto-intersezioni
|
|
int nCount ;
|
|
if ( ExeCurveSelfIntersCount( nId, &nCount))
|
|
LuaSetParam( L, nCount) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCurveMinAreaRectangleXY( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero i dati del rettangolo
|
|
Frame3d frRect ;
|
|
double dDimX ;
|
|
double dDimY ;
|
|
bool bOk = ExeCurveMinAreaRectangleXY( nId, nRefId, frRect, dDimX, dDimY) ;
|
|
if ( bOk) {
|
|
LuaSetParam( L, frRect) ;
|
|
LuaSetParam( L, dDimX) ;
|
|
LuaSetParam( L, dDimY) ;
|
|
return 3 ;
|
|
}
|
|
else {
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaArcRadius( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero il raggio
|
|
double dRad ;
|
|
if ( ExeArcRadius( nId, &dRad))
|
|
LuaSetParam( L, dRad) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaArcAngCenter( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero l'angolo al centro in gradi
|
|
double pdAngDeg ;
|
|
if ( ExeArcAngCenter( nId, &pdAngDeg))
|
|
LuaSetParam( L, pdAngDeg) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaArcDeltaN( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero il delta su normale al suo piano
|
|
double dDeltaN ;
|
|
if ( ExeArcDeltaN( nId, &dDeltaN))
|
|
LuaSetParam( L, dDeltaN) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaArcNormVersor( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il versore
|
|
Vector3d vtNorm ;
|
|
if ( ExeArcNormVersor( nId, nRefId, vtNorm))
|
|
LuaSetParam( L, vtNorm) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCurveCompoCenter( lua_State* L)
|
|
{
|
|
// 2 o 3 parametri : Id, nCrv [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nCrv ;
|
|
LuaCheckParam( L, 2, nCrv)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 3, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il centro della curva semplice indicizzata
|
|
Point3d ptCen ;
|
|
if ( ExeCurveCompoCenter( nId, nCrv, nRefId, ptCen))
|
|
LuaSetParam( L, ptCen) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfArea( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero la sua area
|
|
double dArea ;
|
|
if ( ExeSurfArea( nId, dArea))
|
|
LuaSetParam( L, dArea) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfVolume( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero il suo eventuale volume (se chiusa)
|
|
double dVol ;
|
|
if ( ExeSurfVolume( nId, dVol))
|
|
LuaSetParam( L, dVol) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfFrNormVersor( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il versore
|
|
Vector3d vtNorm ;
|
|
if ( ExeSurfFrNormVersor( nId, nRefId, vtNorm))
|
|
LuaSetParam( L, vtNorm) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfFrChunkCount( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero il numero di componenti connessi (chunk) della regione
|
|
int nNbr = ExeSurfFrChunkCount( nId) ;
|
|
LuaSetParam( L, nNbr) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfFrChunkSimpleClassify( lua_State* L)
|
|
{
|
|
// 4 parametro : Id1, Chunk1, Id2, Chunk2
|
|
int nId1 ;
|
|
LuaCheckParam( L, 1, nId1)
|
|
int nChunk1 ;
|
|
LuaCheckParam( L, 2, nChunk1)
|
|
int nId2 ;
|
|
LuaCheckParam( L, 3, nId2)
|
|
int nChunk2 ;
|
|
LuaCheckParam( L, 4, nChunk2)
|
|
LuaClearStack( L) ;
|
|
// classifico il chunk della prima regione rispetto a quello della seconda
|
|
int nClass = ExeSurfFrChunkSimpleClassify( nId1, nChunk1, nId2, nChunk2) ;
|
|
LuaSetParam( L, nClass) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfTmFacetCount( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero il numero di facce della superficie trimesh
|
|
int nNbr = ExeSurfTmFacetCount( nId) ;
|
|
LuaSetParam( L, nNbr) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfTmFacetAdjacencies( lua_State* L)
|
|
{
|
|
// 2 parametri : nId, nFacet
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nFacet ;
|
|
LuaCheckParam( L, 2, nFacet)
|
|
LuaClearStack( L) ;
|
|
// recupero le adiacenze della faccetta della superficie
|
|
INTMATRIX vAdj ;
|
|
bool bOk = ExeSurfTmFacetAdjacencies( nId, nFacet, vAdj) ;
|
|
// restituisco il risultato
|
|
if ( bOk)
|
|
LuaSetParam( L, vAdj) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfTmFacetNearestEndPoint( lua_State* L)
|
|
{
|
|
// 3 o 4 parametri : Id, nFacet, ptNear [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nFacet ;
|
|
LuaCheckParam( L, 2, nFacet)
|
|
Point3d ptNear ;
|
|
LuaCheckParam( L, 3, ptNear)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 4, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il punto End più vicino della faccia della superficie trimesh
|
|
Point3d ptEnd ;
|
|
Vector3d vtN ;
|
|
if ( ExeSurfTmFacetNearestEndPoint( nId, nFacet, ptNear, nRefId, ptEnd, vtN)) {
|
|
LuaSetParam( L, ptEnd) ;
|
|
LuaSetParam( L, vtN) ;
|
|
}
|
|
else {
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L) ;
|
|
}
|
|
return 2 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfTmFacetNearestMidPoint( lua_State* L)
|
|
{
|
|
// 3 o 4 parametri : Id, nFacet, ptNear [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nFacet ;
|
|
LuaCheckParam( L, 2, nFacet)
|
|
Point3d ptNear ;
|
|
LuaCheckParam( L, 3, ptNear)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 4, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il punto Mid più vicino della faccia della superficie trimesh
|
|
Point3d ptMid ;
|
|
Vector3d vtN ;
|
|
if ( ExeSurfTmFacetNearestMidPoint( nId, nFacet, ptNear, nRefId, ptMid, vtN)) {
|
|
LuaSetParam( L, ptMid) ;
|
|
LuaSetParam( L, vtN) ;
|
|
}
|
|
else {
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L) ;
|
|
}
|
|
return 2 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfTmFacetCenter( lua_State* L)
|
|
{
|
|
// 2 o 3 parametri : Id, nFacet [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nFacet ;
|
|
LuaCheckParam( L, 2, nFacet)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 3, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il centro della faccia della superficie trimesh
|
|
Point3d ptCen ;
|
|
Vector3d vtN ;
|
|
if ( ExeSurfTmFacetCenter( nId, nFacet, nRefId, ptCen, vtN)) {
|
|
LuaSetParam( L, ptCen) ;
|
|
LuaSetParam( L, vtN) ;
|
|
}
|
|
else {
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L) ;
|
|
}
|
|
return 2 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfTmFacetNormVersor( lua_State* L)
|
|
{
|
|
// 2 o 3 parametri : Id, nFacet [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nFacet ;
|
|
LuaCheckParam( L, 2, nFacet)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 3, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero la normale della faccia della superficie trimesh
|
|
Vector3d vtNorm ;
|
|
if ( ExeSurfTmFacetNormVersor( nId, nFacet, nRefId, vtNorm))
|
|
LuaSetParam( L, vtNorm) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfTmFacetsContact( lua_State* L)
|
|
{
|
|
// 3 o 4 parametri : Id, nF1, nF2 [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nF1 ;
|
|
LuaCheckParam( L, 2, nF1)
|
|
int nF2 ;
|
|
LuaCheckParam( L, 3, nF2)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 4, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero i dati di contatto tra le due facce
|
|
bool bAdjac ;
|
|
Point3d ptP1, ptP2 ;
|
|
double dAng = 0 ;
|
|
if ( ExeSurfTmFacetsContact( nId, nF1, nF2, nRefId, bAdjac, ptP1, ptP2, dAng)) {
|
|
LuaSetParam( L, bAdjac) ;
|
|
LuaSetParam( L, ptP1) ;
|
|
LuaSetParam( L, ptP2) ;
|
|
LuaSetParam( L, dAng) ;
|
|
}
|
|
else {
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L) ;
|
|
}
|
|
return 4 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaVolZmapVolume( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero il suo volume
|
|
double dVol ;
|
|
if ( ExeVolZmapVolume( nId, dVol))
|
|
LuaSetParam( L, dVol) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaVolZmapPartCount( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero il numero di parti del solido Zmap
|
|
int nParts = ExeVolZmapPartCount( nId) ;
|
|
if ( nParts >= 0)
|
|
LuaSetParam( L, nParts) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaVolZmapPartVolume( lua_State* L)
|
|
{
|
|
// 2 parametri : Id, nPartInd (0-based)
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nPartInd ;
|
|
LuaCheckParam( L, 2, nPartInd)
|
|
LuaClearStack( L) ;
|
|
// recupero il suo eventuale volume
|
|
double dVol ;
|
|
if ( ExeVolZmapPartVolume( nId, nPartInd, dVol))
|
|
LuaSetParam( L, dVol) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaTextNormVersor( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : Id [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
int nRefId = nId ;
|
|
LuaGetParam( L, 2, nRefId) ;
|
|
LuaClearStack( L) ;
|
|
// recupero il versore
|
|
Vector3d vtNorm ;
|
|
if ( ExeTextNormVersor( nId, nRefId, vtNorm))
|
|
LuaSetParam( L, vtNorm) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
bool
|
|
LuaInstallGeoSnap( LuaMgr& luaMgr)
|
|
{
|
|
bool bOk = ( &luaMgr != nullptr) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSP", LuaStartPoint) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtEP", LuaEndPoint) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtMP", LuaMidPoint) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCP", LuaCenterPoint) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtGP", LuaCentroid) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtUP", LuaAtParamPoint) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtNP", LuaNearPoint) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtIP", LuaIntersectionPoint) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSV", LuaStartVector) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtEV", LuaEndVector) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtMV", LuaMidVector) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtUV", LuaAtParamVector) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtFR", LuaFrame) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtET", LuaExtrusionByThickness) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCurveDomain", LuaCurveDomain) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCurveLength", LuaCurveLength) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCurveIsClosed", LuaCurveIsClosed) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCurveIsFlat", LuaCurveIsFlat) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCurveAreaXY", LuaCurveAreaXY) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCurveArea", LuaCurveArea) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCurveExtrusion", LuaCurveExtrusion) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCurveThickness", LuaCurveThickness) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCurveSelfIntersCount", LuaCurveSelfIntersCount) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCurveMinAreaRectangleXY", LuaCurveMinAreaRectangleXY) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtArcRadius", LuaArcRadius) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtArcAngCenter", LuaArcAngCenter) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtArcDeltaN", LuaArcDeltaN) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtArcNormVersor", LuaArcNormVersor) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCompoCenter", LuaCurveCompoCenter) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfArea", LuaSurfArea) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfVolume", LuaSurfVolume) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrNormVersor", LuaSurfFrNormVersor) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrChunkCount", LuaSurfFrChunkCount) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrChunkSimpleClassify", LuaSurfFrChunkSimpleClassify) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetCount", LuaSurfTmFacetCount) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetAdjacencies", LuaSurfTmFacetAdjacencies) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetNearestEndPoint", LuaSurfTmFacetNearestEndPoint) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetNearestMidPoint", LuaSurfTmFacetNearestMidPoint) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetCenter", LuaSurfTmFacetCenter) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetNormVersor", LuaSurfTmFacetNormVersor) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetsContact", LuaSurfTmFacetsContact) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapVolume", LuaVolZmapVolume) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapPartCount", LuaVolZmapPartCount) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapPartVolume", LuaVolZmapPartVolume) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtTextNormVersor", LuaTextNormVersor) ;
|
|
return bOk ;
|
|
}
|