Files
EgtInterface/LUA_GeoSnap.cpp
T
Dario Sassi bebcf1ecfe EgtInterface 1.5l2 :
- migliorie e modifiche in generale, specie su Lua.
2014-12-30 17:36:43 +00:00

475 lines
13 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 "API.h"
#include "/EgtDev/Include/EInAPI.h"
#include "/EgtDev/Include/EgnStringUtils.h"
#include "/EgtDev/Extern/Lua/Include/lua.hpp"
using namespace std ;
//----------------------------------------------------------------------------
static int
LuaStartPoint( lua_State* L)
{
// 1 o 2 parametri : Id [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
int nRefId = nId ;
if ( lua_gettop( L) >= 2) {
if ( ! LuaGetParam( L, 2, nRefId)) {
string sFlag ;
LuaCheckParam( L, 2, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il punto iniziale dell'entità
Point3d ptP ;
if ( EgtStartPoint( nId, nRefId, ptP))
LuaSetReturn( L, ptP) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaEndPoint( lua_State* L)
{
// 1 o 2 parametri : Id [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
int nRefId = nId ;
if ( lua_gettop( L) >= 2) {
if ( ! LuaGetParam( L, 2, nRefId)) {
string sFlag ;
LuaCheckParam( L, 2, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il punto finale dell'entità
Point3d ptP ;
if ( EgtEndPoint( nId, nRefId, ptP))
LuaSetReturn( L, ptP) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaMidPoint( lua_State* L)
{
// 1 o 2 parametri : Id [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
int nRefId = nId ;
if ( lua_gettop( L) >= 2) {
if ( ! LuaGetParam( L, 2, nRefId)) {
string sFlag ;
LuaCheckParam( L, 2, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il punto centrale dell'entità
Point3d ptP ;
if ( EgtMidPoint( nId, nRefId, ptP))
LuaSetReturn( L, ptP) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaCenterPoint( lua_State* L)
{
// 1 o 2 parametri : Id [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
int nRefId = nId ;
if ( lua_gettop( L) >= 2) {
if ( ! LuaGetParam( L, 2, nRefId)) {
string sFlag ;
LuaCheckParam( L, 2, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il punto centrale dell'entità
Point3d ptP ;
if ( EgtCenterPoint( nId, nRefId, ptP))
LuaSetReturn( L, ptP) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaAtParamPoint( lua_State* L)
{
// 2 o 3 parametri : Id, U [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
double dU ;
LuaCheckParam( L, 2, dU)
int nRefId = nId ;
if ( lua_gettop( L) >= 3) {
if ( ! LuaGetParam( L, 3, nRefId)) {
string sFlag ;
LuaCheckParam( L, 3, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il punto in posizione parametrica U della curva
Point3d ptP ;
if ( EgtAtParamPoint( nId, dU, nRefId, ptP))
LuaSetReturn( L, ptP) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaNearPoint( lua_State* L)
{
// 2 o 3 parametri : Id, ptNear [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
Point3d ptNear ;
LuaCheckParam( L, 2, ptNear)
int nRefId = nId ;
if ( lua_gettop( L) >= 3) {
if ( ! LuaGetParam( L, 3, nRefId)) {
string sFlag ;
LuaCheckParam( L, 3, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il punto di intersezione tra le curve più vicino al punto passato
Point3d ptP ;
if ( EgtNearPoint( nId, ptNear, nRefId, ptP))
LuaSetReturn( L, ptP) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaIntersectionPoint( lua_State* L)
{
// 3 o 4 parametri : Id1, Id2, ptNear [, nRefIf]
int nId1 ;
LuaCheckParam( L, 1, nId1)
int nId2 ;
LuaCheckParam( L, 2, nId2)
Point3d ptNear ;
LuaCheckParam( L, 3, ptNear)
int nRefId = nId1 ;
if ( lua_gettop( L) >= 4) {
if ( ! LuaGetParam( L, 4, nRefId)) {
string sFlag ;
LuaCheckParam( L, 4, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il punto di intersezione tra le curve più vicino al punto passato
Point3d ptP ;
if ( EgtIntersectionPoint( nId1, nId2, ptNear, nRefId, ptP))
LuaSetReturn( L, ptP) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaStartVector( lua_State* L)
{
// 1 o 2 parametri : Id [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
int nRefId = nId ;
if ( lua_gettop( L) >= 2) {
if ( ! LuaGetParam( L, 2, nRefId)) {
string sFlag ;
LuaCheckParam( L, 2, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il vettore tangente all'inizio della curva
Vector3d vtV ;
if ( EgtStartVector( nId, nRefId, vtV))
LuaSetReturn( L, vtV) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaEndVector( lua_State* L)
{
// 1 o 2 parametri : Id [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
int nRefId = nId ;
if ( lua_gettop( L) >= 2) {
if ( ! LuaGetParam( L, 2, nRefId)) {
string sFlag ;
LuaCheckParam( L, 2, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il vettore tangente alla fine della curva
Vector3d vtV ;
if ( EgtEndVector( nId, nRefId, vtV))
LuaSetReturn( L, vtV) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaMidVector( lua_State* L)
{
// 1 o 2 parametri : Id [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
int nRefId = nId ;
if ( lua_gettop( L) >= 2) {
if ( ! LuaGetParam( L, 2, nRefId)) {
string sFlag ;
LuaCheckParam( L, 2, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il vettore tangente nel punto medio della curva
Vector3d vtV ;
if ( EgtMidVector( nId, nRefId, vtV))
LuaSetReturn( L, vtV) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaAtParamVector( lua_State* L)
{
// 2, 3 o 4 parametri : Id, U, sSide [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
double dU ;
LuaCheckParam( L, 2, dU)
int nSide = + 1 ;
string sSide ;
LuaCheckParam( L, 3, sSide) ;
if ( sSide == "-")
nSide = - 1 ;
int nRefId = nId ;
if ( lua_gettop( L) >= 4) {
if ( ! LuaGetParam( L, 4, nRefId)) {
string sFlag ;
LuaCheckParam( L, 4, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il punto in posizione parametrica U della curva
Vector3d vtV ;
if ( EgtAtParamVector( nId, dU, nSide, nRefId, vtV))
LuaSetReturn( L, vtV) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaFrame( lua_State* L)
{
// 1 o 2 parametri : Id [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
int nRefId = nId ;
if ( lua_gettop( L) >= 2) {
if ( ! LuaGetParam( L, 2, nRefId)) {
string sFlag ;
LuaCheckParam( L, 2, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il frame
Frame3d frFrame ;
if ( EgtFrame( nId, nRefId, frFrame))
LuaSetReturn( L, frFrame) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaCurveExtrusion( lua_State* L)
{
// 1 o 2 parametri : Id [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
int nRefId = nId ;
if ( lua_gettop( L) >= 2) {
if ( ! LuaGetParam( L, 2, nRefId)) {
string sFlag ;
LuaCheckParam( L, 2, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il versore
Vector3d vtExtr ;
if ( EgtCurveExtrusion( nId, nRefId, vtExtr))
LuaSetReturn( L, vtExtr) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaCurveThickness( lua_State* L)
{
// 1 parametro : Id
int nId ;
LuaCheckParam( L, 1, nId)
int nRefId = nId ;
LuaClearStack( L) ;
// recupero lo spessore
double dThick ;
if ( EgtCurveThickness( nId, &dThick) != FALSE)
LuaSetReturn( L, dThick) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaCurveArcNormVersor( lua_State* L)
{
// 1 o 2 parametri : Id [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
int nRefId = nId ;
if ( lua_gettop( L) >= 2) {
if ( ! LuaGetParam( L, 2, nRefId)) {
string sFlag ;
LuaCheckParam( L, 2, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il versore
Vector3d vtNorm ;
if ( EgtCurveArcNormVersor( nId, nRefId, vtNorm))
LuaSetReturn( L, vtNorm) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaExtTextNormVersor( lua_State* L)
{
// 1 o 2 parametri : Id [, nRefIf]
int nId ;
LuaCheckParam( L, 1, nId)
int nRefId = nId ;
if ( lua_gettop( L) >= 2) {
if ( ! LuaGetParam( L, 2, nRefId)) {
string sFlag ;
LuaCheckParam( L, 2, sFlag)
ToUpper( sFlag) ;
nRefId = (( sFlag == "GRID") ? GDB_ID_GRID : GDB_ID_ROOT) ;
}
}
LuaClearStack( L) ;
// recupero il versore
Vector3d vtNorm ;
if ( EgtExtTextNormVersor( nId, nRefId, vtNorm))
LuaSetReturn( L, vtNorm) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//-------------------------------------------------------------------------------
bool
LuaInstallGeoSnap( lua_State* L)
{
try {
lua_register( L, "EgtSP", LuaStartPoint) ;
lua_register( L, "EgtEP", LuaEndPoint) ;
lua_register( L, "EgtMP", LuaMidPoint) ;
lua_register( L, "EgtCP", LuaCenterPoint) ;
lua_register( L, "EgtUP", LuaAtParamPoint) ;
lua_register( L, "EgtNP", LuaNearPoint) ;
lua_register( L, "EgtIP", LuaIntersectionPoint) ;
lua_register( L, "EgtSV", LuaStartVector) ;
lua_register( L, "EgtEV", LuaEndVector) ;
lua_register( L, "EgtMV", LuaMidVector) ;
lua_register( L, "EgtUV", LuaAtParamVector) ;
lua_register( L, "EgtFR", LuaFrame) ;
lua_register( L, "EgtCurveExtrusion", LuaCurveExtrusion) ;
lua_register( L, "EgtCurveThickness", LuaCurveThickness) ;
lua_register( L, "EgtCurveArcNormVersor", LuaCurveArcNormVersor) ;
lua_register( L, "EgtExtTextNormVersor", LuaExtTextNormVersor) ;
}
catch ( ...) {
return false ;
}
return true ;
}