Files
Include/EGkLuaAux.h
T
SaraP ee01a02292 Include :
- aggiunti prototipi per calcolo shear sequence nel nesting
- aggiunta funzione LuaSetParam per vettore di punti.
2025-09-12 10:20:30 +02:00

503 lines
14 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2015-2024
//----------------------------------------------------------------------------
// File : EGkLuaAux.h Data : 08.05.24 Versione : 2.6e2
// Contenuto : Funzioni per gestione parametri geometrici con LUA.
//
//
//
// Modifiche : 21.03.15 DS Creazione modulo.
// 14.04.24 DS Aggiunta gestione Quaternion.
// 08.05.24 DS Aggiunta LuaSetParam per VCT3DVECTOR.
//
//----------------------------------------------------------------------------
#pragma once
#include "/EgtDev/Include/EGkVector3d.h"
#include "/EgtDev/Include/EGkPoint3d.h"
#include "/EgtDev/Include/EGkFrame3d.h"
#include "/EgtDev/Include/EGkBBox3d.h"
#include "/EgtDev/Include/EGkQuaternion.h"
#include "/EgtDev/Include/EGkColor.h"
#include "/EgtDev/Include/EGkGeoCollection.h"
#include "/EgtDev/Include/EGkSelection.h"
#include "/EgtDev/Include/EGnLuaAux.h"
//----------------------------------------------------------------------------
inline bool
LuaGetParam( lua_State* L, int nInd, Vector3d& vtPar)
{
return LuaGetParam( L, nInd, vtPar.v) ;
}
//----------------------------------------------------------------------------
inline bool
LuaGetParam( lua_State* L, int nInd, Point3d& ptPar)
{
return LuaGetParam( L, nInd, ptPar.v) ;
}
//----------------------------------------------------------------------------
inline bool
LuaGetParam( lua_State* L, int nInd, POINTU& ptParW)
{
if ( ! lua_istable( L, nInd))
return false ;
for ( int i = 1 ; i <= 4 ; ++ i) {
lua_rawgeti( L, nInd, i) ;
if ( ! lua_isnumber( L, -1))
return false ;
if ( i <= 3)
ptParW.first.v[i-1] = lua_tonumber( L, -1) ;
else
ptParW.second = lua_tonumber( L, -1) ;
lua_pop( L, 1) ;
}
return true ;
}
//----------------------------------------------------------------------------
inline bool
LuaGetParam( lua_State* L, int nInd, Frame3d& frPar)
{
if ( ! lua_istable( L, nInd))
return false ;
// recupero l'origine
lua_rawgeti( L, nInd, 1) ;
Point3d ptOrig ;
if ( ! LuaGetParam( L, -1, ptOrig))
return false ;
lua_pop( L, 1) ;
// recupero il versore X
lua_rawgeti( L, nInd, 2) ;
Vector3d vtDirX ;
if ( ! LuaGetParam( L, -1, vtDirX))
return false ;
lua_pop( L, 1) ;
// recupero il versore Y
lua_rawgeti( L, nInd, 3) ;
Vector3d vtDirY ;
if ( ! LuaGetParam( L, -1, vtDirY))
return false ;
lua_pop( L, 1) ;
// recupero il versore Z
lua_rawgeti( L, nInd, 4) ;
Vector3d vtDirZ ;
if ( ! LuaGetParam( L, -1, vtDirZ))
return false ;
lua_pop( L, 1) ;
// assegno il riferimento
return frPar.Set( ptOrig, vtDirX, vtDirY, vtDirZ) ;
}
//----------------------------------------------------------------------------
inline bool
LuaGetParam( lua_State* L, int nInd, BBox3d& b3Par)
{
if ( ! lua_istable( L, nInd))
return false ;
// recupero il minimo
lua_rawgeti( L, nInd, 1) ;
Point3d ptMin ;
if ( ! LuaGetParam( L, -1, ptMin))
return false ;
lua_pop( L, 1) ;
// recupero il massimo
lua_rawgeti( L, nInd, 2) ;
Point3d ptMax ;
if ( ! LuaGetParam( L, -1, ptMax))
return false ;
lua_pop( L, 1) ;
// assegno il box
if ( ptMin.x < ( ptMax.x + EPS_SMALL) &&
ptMin.y < ( ptMax.y + EPS_SMALL) &&
ptMin.z < ( ptMax.z + EPS_SMALL))
b3Par.Set( ptMin, ptMax) ;
else
b3Par.Reset() ;
return true ;
}
//----------------------------------------------------------------------------
inline bool
LuaGetParam( lua_State* L, int nInd, Quaternion& qtPar)
{
return LuaGetParam( L, nInd, qtPar.v) ;
}
//----------------------------------------------------------------------------
inline bool
LuaGetParam( lua_State* L, int nInd, Color& colPar)
{
if ( ! lua_istable( L, nInd))
return false ;
int nCol[4] ;
// red, gree, blue
for ( int i = 1 ; i <= 3 ; ++ i) {
lua_rawgeti( L, nInd, i) ;
if ( ! lua_isnumber( L, -1))
return false ;
nCol[i-1] = int( lua_tonumber( L, -1) + 0.5) ;
lua_pop( L, 1) ;
}
// alpha opzionale
lua_rawgeti( L, nInd, 4) ;
if ( lua_isnumber( L, -1))
nCol[3] = int( lua_tonumber( L, -1) + 0.5) ;
else
nCol[3] = 100 ;
lua_pop( L, 1) ;
// assegno il colore
colPar.Set( nCol[0], nCol[1], nCol[2], nCol[3]) ;
return true ;
}
//----------------------------------------------------------------------------
inline bool
LuaGetParam( lua_State* L, int nInd, PNTVECTOR& vPar)
{
vPar.clear() ;
Point3d ptP ;
if ( LuaGetParam( L, nInd, ptP)) {
vPar.push_back( ptP) ;
return true ;
}
else if ( lua_istable( L, nInd)) {
// lunghezza della tavola
lua_len( L, nInd) ;
if ( ! lua_isnumber( L, -1))
return false ;
int nLen = int( lua_tointeger( L, -1)) ;
lua_pop( L, 1) ;
vPar.reserve( nLen) ;
for ( int i = 1 ; i <= nLen ; ++ i) {
lua_rawgeti( L, nInd, i) ;
Point3d ptP ;
if ( ! LuaGetParam( L, -1, ptP))
return false ;
vPar.push_back( ptP) ;
lua_pop( L, 1) ;
}
return true ;
}
else
return false ;
}
//----------------------------------------------------------------------------
inline bool
LuaGetParam( lua_State* L, int nInd, PNTUVECTOR& vParW)
{
vParW.clear() ;
POINTU ptPW ;
if ( LuaGetParam( L, nInd, ptPW)) {
vParW.push_back( ptPW) ;
return true ;
}
else if ( lua_istable( L, nInd)) {
// lunghezza della tavola
lua_len( L, nInd) ;
if ( ! lua_isnumber( L, -1))
return false ;
int nLen = int( lua_tointeger( L, -1)) ;
lua_pop( L, 1) ;
vParW.reserve( nLen) ;
for ( int i = 1 ; i <= nLen ; ++ i) {
lua_rawgeti( L, nInd, i) ;
POINTU ptPW ;
if ( ! LuaGetParam( L, -1, ptPW))
return false ;
vParW.push_back( ptPW) ;
lua_pop( L, 1) ;
}
return true ;
}
else
return false ;
}
//----------------------------------------------------------------------------
inline bool
LuaGetParam( lua_State* L, int nInd, SELVECTOR& vSel)
{
vSel.clear() ;
int nId ;
if ( LuaGetParam( L, nInd, nId)) {
vSel.emplace_back( nId) ;
return true ;
}
else if ( lua_istable( L, nInd)) {
// lunghezza della tavola
lua_len( L, nInd) ;
if ( ! lua_isnumber( L, -1))
return false ;
int nLen = int( lua_tointeger( L, -1)) ;
lua_pop( L, 1) ;
// recupero il contenuto della tavola
vSel.reserve( nLen) ;
for ( int i = 1 ; i <= nLen ; ++ i) {
lua_rawgeti( L, nInd, i) ;
int nId ;
if ( LuaGetParam( L, -1, nId)) {
vSel.emplace_back( nId) ;
lua_pop( L, 1) ;
}
else {
SelData Id ;
if ( ! LuaGetParam( L, -1, Id.v))
return false ;
vSel.emplace_back( Id) ;
lua_pop( L, 1) ;
}
}
return true ;
}
else
return false ;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
inline bool
LuaSetParam( lua_State* L, const Vector3d& vtPar)
{
try {
lua_createtable( L, 3, 0) ;
for ( int i = 1 ; i <= 3 ; ++ i) {
lua_pushnumber( L, vtPar.v[i-1]) ;
lua_rawseti( L, -2, i) ;
}
}
catch( ...) {
return false ;
}
return true ;
}
//-------------------------------------------------------------------------------
inline bool
LuaSetParam( lua_State* L, const PNTVECTOR& vPar)
{
try {
// recupero dimensione vettore
int nDim = int( vPar.size()) ;
// creo tavola principale
lua_createtable( L, nDim, 0) ;
// creo e inserisco tavola per ogni componente
for ( int i = 1 ; i <= nDim ; ++ i) {
// creo tavola componente
lua_createtable( L, 3, 0) ;
for ( int j = 1 ; j <= 3 ; ++ j) {
lua_pushnumber( L, vPar[i-1].v[j-1]) ;
lua_rawseti( L, -2, j) ;
}
// la metto nel vettore
lua_rawseti( L, -2, i) ;
}
}
catch( ...) {
return false ;
}
return true ;
}
//-------------------------------------------------------------------------------
inline bool
LuaSetParam( lua_State* L, const VCT3DVECTOR& vPar)
{
try {
// recupero dimensione vettore
int nDim = int( vPar.size()) ;
// creo tavola principale
lua_createtable( L, nDim, 0) ;
// creo e inserisco tavola per ogni componente
for ( int i = 1 ; i <= nDim ; ++ i) {
// creo tavola componente
lua_createtable( L, 3, 0) ;
for ( int j = 1 ; j <= 3 ; ++ j) {
lua_pushnumber( L, vPar[i-1].v[j-1]) ;
lua_rawseti( L, -2, j) ;
}
// la metto nel vettore
lua_rawseti( L, -2, i) ;
}
}
catch( ...) {
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
inline bool
LuaSetParam( lua_State* L, const Point3d& ptPar)
{
try {
lua_createtable( L, 3, 0) ;
for ( int i = 1 ; i <= 3 ; ++ i) {
lua_pushnumber( L, ptPar.v[i-1]) ;
lua_rawseti( L, -2, i) ;
}
}
catch( ...) {
return false ;
}
return true ;
}
//-------------------------------------------------------------------------------
inline bool
LuaSetParam( lua_State* L, const Frame3d& frPar)
{
try {
// creo tavola per frame
lua_createtable( L, 4, 0) ;
// creo tavola per origine
lua_createtable( L, 3, 0) ;
lua_pushnumber( L, frPar.Orig().x) ;
lua_rawseti( L, -2, 1) ;
lua_pushnumber( L, frPar.Orig().y) ;
lua_rawseti( L, -2, 2) ;
lua_pushnumber( L, frPar.Orig().z) ;
lua_rawseti( L, -2, 3) ;
// la metto nel frame
lua_rawseti( L, -2, 1) ;
// creo tavola per versore X
lua_createtable( L, 3, 0) ;
lua_pushnumber( L, frPar.VersX().x) ;
lua_rawseti( L, -2, 1) ;
lua_pushnumber( L, frPar.VersX().y) ;
lua_rawseti( L, -2, 2) ;
lua_pushnumber( L, frPar.VersX().z) ;
lua_rawseti( L, -2, 3) ;
// la metto nel frame
lua_rawseti( L, -2, 2) ;
// creo tavola per versore Y
lua_createtable( L, 3, 0) ;
lua_pushnumber( L, frPar.VersY().x) ;
lua_rawseti( L, -2, 1) ;
lua_pushnumber( L, frPar.VersY().y) ;
lua_rawseti( L, -2, 2) ;
lua_pushnumber( L, frPar.VersY().z) ;
lua_rawseti( L, -2, 3) ;
// la metto nel frame
lua_rawseti( L, -2, 3) ;
// creo tavola per versore Z
lua_createtable( L, 3, 0) ;
lua_pushnumber( L, frPar.VersZ().x) ;
lua_rawseti( L, -2, 1) ;
lua_pushnumber( L, frPar.VersZ().y) ;
lua_rawseti( L, -2, 2) ;
lua_pushnumber( L, frPar.VersZ().z) ;
lua_rawseti( L, -2, 3) ;
// la metto nel frame
lua_rawseti( L, -2, 4) ;
}
catch( ...) {
return false ;
}
return true ;
}
//-------------------------------------------------------------------------------
inline bool
LuaSetParam( lua_State* L, const BBox3d& b3Par)
{
try {
// creo tavola per bbox
lua_createtable( L, 2, 0) ;
// creo tavola per minimo
lua_createtable( L, 3, 0) ;
lua_pushnumber( L, b3Par.GetMin().x) ;
lua_rawseti( L, -2, 1) ;
lua_pushnumber( L, b3Par.GetMin().y) ;
lua_rawseti( L, -2, 2) ;
lua_pushnumber( L, b3Par.GetMin().z) ;
lua_rawseti( L, -2, 3) ;
// la metto nel frame
lua_rawseti( L, -2, 1) ;
// creo tavola per massimo
lua_createtable( L, 3, 0) ;
lua_pushnumber( L, b3Par.GetMax().x) ;
lua_rawseti( L, -2, 1) ;
lua_pushnumber( L, b3Par.GetMax().y) ;
lua_rawseti( L, -2, 2) ;
lua_pushnumber( L, b3Par.GetMax().z) ;
lua_rawseti( L, -2, 3) ;
// la metto nel frame
lua_rawseti( L, -2, 2) ;
}
catch( ...) {
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
inline bool
LuaSetParam( lua_State* L, const Quaternion& qtPar)
{
try {
lua_createtable( L, 4, 0) ;
for ( int i = 1 ; i <= 4 ; ++ i) {
lua_pushnumber( L, qtPar.v[i-1]) ;
lua_rawseti( L, -2, i) ;
}
}
catch( ...) {
return false ;
}
return true ;
}
//-------------------------------------------------------------------------------
inline bool
LuaSetParam( lua_State* L, const Color& colPar)
{
try {
lua_createtable( L, 4, 0) ;
lua_pushinteger( L, colPar.GetIntRed()) ;
lua_rawseti( L, -2, 1) ;
lua_pushinteger( L, colPar.GetIntGreen()) ;
lua_rawseti( L, -2, 2) ;
lua_pushinteger( L, colPar.GetIntBlue()) ;
lua_rawseti( L, -2, 3) ;
lua_pushinteger( L, colPar.GetIntAlpha()) ;
lua_rawseti( L, -2, 4) ;
}
catch( ...) {
return false ;
}
return true ;
}
//-------------------------------------------------------------------------------
inline bool
LuaSetParam( lua_State* L, const SELVECTOR& vSel)
{
try {
// recupero dimensione
int nDim = int( vSel.size()) ;
// creo tavola per vSel
lua_createtable( L, nDim, 0) ;
// creo e inserisco tavola per ogni componente
for ( int i = 1 ; i <= nDim ; ++ i) {
// creo tavola
lua_createtable( L, 2, 0) ;
lua_pushinteger( L, vSel[i-1].nId) ;
lua_rawseti( L, -2, 1) ;
lua_pushinteger( L, vSel[i-1].nSub) ;
lua_rawseti( L, -2, 2) ;
// la metto nel vettore
lua_rawseti( L, -2, i) ;
}
}
catch( ...) {
return false ;
}
return true ;
}