d71d932772
- adattamenti e modifiche per superfici di Bezier estese.
323 lines
9.0 KiB
C++
323 lines
9.0 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2020
|
|
//----------------------------------------------------------------------------
|
|
// File : LUA_GeoSnap.cpp Data : 06.02.20 Versione : 2.2b2
|
|
// 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/EXeConst.h"
|
|
#include "/EgtDev/Include/EGkLuaAux.h"
|
|
|
|
//----------------------------------------------------------------------------
|
|
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)
|
|
{
|
|
// 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
|
|
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) && abs( dThick) > EPS_SMALL)
|
|
vtExtr *= dThick ;
|
|
else
|
|
vtExtr = V_NULL ;
|
|
LuaSetParam( L, vtExtr) ;
|
|
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) ;
|
|
return bOk ;
|
|
}
|