bebcf1ecfe
- migliorie e modifiche in generale, specie su Lua.
323 lines
9.2 KiB
C++
323 lines
9.2 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : LUA_GdbObjects.cpp Data : 30.09.14 Versione : 1.5i5
|
|
// Contenuto : Funzioni di iterazione di DB geometrico per LUA.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 30.09.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
|
|
LuaExistsObj( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// verifico esistenza oggetto
|
|
bool bOk = ( EgtExistsObj( nId) != FALSE) ;
|
|
// restituisco il risultato
|
|
LuaSetReturn( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaGetGroupObjs( lua_State* L)
|
|
{
|
|
// 1 parametro : GroupId
|
|
int nGroupId ;
|
|
LuaCheckParam( L, 1, nGroupId)
|
|
LuaClearStack( L) ;
|
|
// determino il numero di oggetti nel gruppo
|
|
int nObjs = EgtGetGroupObjs( nGroupId) ;
|
|
// restituisco il risultato
|
|
LuaSetReturn( L, nObjs) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaGetFirstInGroup( lua_State* L)
|
|
{
|
|
// 1 parametro : GroupId
|
|
int nGroupId ;
|
|
LuaCheckParam( L, 1, nGroupId)
|
|
LuaClearStack( L) ;
|
|
// recupero il primo oggetto del gruppo
|
|
int nId = EgtGetFirstInGroup( nGroupId) ;
|
|
// restituisco il risultato
|
|
if ( nId != GDB_ID_NULL)
|
|
LuaSetReturn( L, nId) ;
|
|
else
|
|
LuaSetReturn( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaGetNext( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero il prossimo oggetto nello stesso gruppo
|
|
int nNextId = EgtGetNext( nId) ;
|
|
// restituisco il risultato
|
|
if ( nNextId != GDB_ID_NULL)
|
|
LuaSetReturn( L, nNextId) ;
|
|
else
|
|
LuaSetReturn( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaGetLastInGroup( lua_State* L)
|
|
{
|
|
// 1 parametro : GroupId
|
|
int nGroupId ;
|
|
LuaCheckParam( L, 1, nGroupId)
|
|
LuaClearStack( L) ;
|
|
// recupero l'ultimo oggetto del gruppo
|
|
int nId = EgtGetLastInGroup( nGroupId) ;
|
|
// restituisco il risultato
|
|
if ( nId != GDB_ID_NULL)
|
|
LuaSetReturn( L, nId) ;
|
|
else
|
|
LuaSetReturn( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaGetPrev( lua_State* L)
|
|
{
|
|
// 1 parametro : Id
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
LuaClearStack( L) ;
|
|
// recupero il precedente oggetto nello stesso gruppo
|
|
int nPrevId = EgtGetPrev( nId) ;
|
|
// restituisco il risultato
|
|
if ( nPrevId != GDB_ID_NULL)
|
|
LuaSetReturn( L, nPrevId) ;
|
|
else
|
|
LuaSetReturn( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaGetFirstNameInGroup( lua_State* L)
|
|
{
|
|
// 2 parametri : GroupId, sName
|
|
int nGroupId ;
|
|
LuaCheckParam( L, 1, nGroupId)
|
|
string sName ;
|
|
LuaCheckParam( L, 2, sName)
|
|
LuaClearStack( L) ;
|
|
// recupero il primo oggetto del gruppo
|
|
int nId = EgtGetFirstNameInGroup( nGroupId, sName) ;
|
|
// restituisco il risultato
|
|
if ( nId != GDB_ID_NULL)
|
|
LuaSetReturn( L, nId) ;
|
|
else
|
|
LuaSetReturn( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaGetNextName( lua_State* L)
|
|
{
|
|
// 2 parametri : Id, sName
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
string sName ;
|
|
LuaCheckParam( L, 2, sName)
|
|
LuaClearStack( L) ;
|
|
// recupero il prossimo oggetto nello stesso gruppo
|
|
int nNextId = EgtGetNextName( nId, sName) ;
|
|
// restituisco il risultato
|
|
if ( nNextId != GDB_ID_NULL)
|
|
LuaSetReturn( L, nNextId) ;
|
|
else
|
|
LuaSetReturn( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaCopy( lua_State* L)
|
|
{
|
|
// 2 o 3 parametri : SouId, RefId [, SonBeforeAfter]
|
|
int nSouId ;
|
|
LuaCheckParam( L, 1, nSouId)
|
|
int nRefId ;
|
|
LuaCheckParam( L, 2, nRefId)
|
|
int nSonBeforeAfter = GDB_SON ;
|
|
if ( lua_gettop( L) >= 3) {
|
|
string sSonBeforeAfter ;
|
|
LuaCheckParam( L, 3, sSonBeforeAfter) ;
|
|
ToUpper( sSonBeforeAfter) ;
|
|
if ( sSonBeforeAfter == "BEFORE")
|
|
nSonBeforeAfter = GDB_BEFORE ;
|
|
else if ( sSonBeforeAfter == "AFTER")
|
|
nSonBeforeAfter = GDB_AFTER ;
|
|
}
|
|
LuaClearStack( L) ;
|
|
// eseguo la copia
|
|
int nNewId = EgtCopy( nSouId, nRefId, nSonBeforeAfter) ;
|
|
// restituisco il risultato
|
|
if ( nNewId != GDB_ID_NULL)
|
|
LuaSetReturn( L, nNewId) ;
|
|
else
|
|
LuaSetReturn( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaCopyGlob( lua_State* L)
|
|
{
|
|
// 2 o 3 parametri : SouId, RefId [, SonBeforeAfter]
|
|
int nSouId ;
|
|
LuaCheckParam( L, 1, nSouId)
|
|
int nRefId ;
|
|
LuaCheckParam( L, 2, nRefId)
|
|
int nSonBeforeAfter = GDB_SON ;
|
|
if ( lua_gettop( L) >= 3) {
|
|
string sSonBeforeAfter ;
|
|
LuaCheckParam( L, 3, sSonBeforeAfter) ;
|
|
ToUpper( sSonBeforeAfter) ;
|
|
if ( sSonBeforeAfter == "BEFORE")
|
|
nSonBeforeAfter = GDB_BEFORE ;
|
|
else if ( sSonBeforeAfter == "AFTER")
|
|
nSonBeforeAfter = GDB_AFTER ;
|
|
}
|
|
LuaClearStack( L) ;
|
|
// eseguo la copia
|
|
int nNewId = EgtCopyGlob( nSouId, nRefId, nSonBeforeAfter) ;
|
|
// restituisco il risultato
|
|
if ( nNewId != GDB_ID_NULL)
|
|
LuaSetReturn( L, nNewId) ;
|
|
else
|
|
LuaSetReturn( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaRelocate( lua_State* L)
|
|
{
|
|
// 2 o 3 parametri : SouId, RefId [, SonBeforeAfter]
|
|
int nSouId ;
|
|
LuaCheckParam( L, 1, nSouId)
|
|
int nRefId ;
|
|
LuaCheckParam( L, 2, nRefId)
|
|
int nSonBeforeAfter = GDB_SON ;
|
|
if ( lua_gettop( L) >= 3) {
|
|
string sSonBeforeAfter ;
|
|
LuaCheckParam( L, 3, sSonBeforeAfter) ;
|
|
ToUpper( sSonBeforeAfter) ;
|
|
if ( sSonBeforeAfter == "BEFORE")
|
|
nSonBeforeAfter = GDB_BEFORE ;
|
|
else if ( sSonBeforeAfter == "AFTER")
|
|
nSonBeforeAfter = GDB_AFTER ;
|
|
}
|
|
LuaClearStack( L) ;
|
|
// eseguo la rilocazione
|
|
bool bOk = ( EgtRelocate( nSouId, nRefId, nSonBeforeAfter) != FALSE) ;
|
|
// restituisco il risultato
|
|
LuaSetReturn( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaRelocateGlob( lua_State* L)
|
|
{
|
|
// 2 o 3 parametri : SouId, RefId [, SonBeforeAfter]
|
|
int nSouId ;
|
|
LuaCheckParam( L, 1, nSouId)
|
|
int nRefId ;
|
|
LuaCheckParam( L, 2, nRefId)
|
|
int nSonBeforeAfter = GDB_SON ;
|
|
if ( lua_gettop( L) >= 3) {
|
|
string sSonBeforeAfter ;
|
|
LuaCheckParam( L, 3, sSonBeforeAfter) ;
|
|
ToUpper( sSonBeforeAfter) ;
|
|
if ( sSonBeforeAfter == "BEFORE")
|
|
nSonBeforeAfter = GDB_BEFORE ;
|
|
else if ( sSonBeforeAfter == "AFTER")
|
|
nSonBeforeAfter = GDB_AFTER ;
|
|
}
|
|
LuaClearStack( L) ;
|
|
// eseguo la rilocazione
|
|
bool bOk = ( EgtRelocateGlob( nSouId, nRefId, nSonBeforeAfter) != FALSE) ;
|
|
// restituisco il risultato
|
|
LuaSetReturn( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaErase( lua_State* L)
|
|
{
|
|
// 1 parametro : Id/s
|
|
INTVECTOR vId ;
|
|
LuaCheckParam( L, 1, vId)
|
|
// eseguo la cancellazione
|
|
bool bOk = true ;
|
|
for ( size_t i = 0 ; i < vId.size() && bOk ; ++ i) {
|
|
if ( EgtErase( vId[i]) == FALSE)
|
|
bOk = false ;
|
|
}
|
|
// restituisco il risultato
|
|
LuaSetReturn( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
bool
|
|
LuaInstallGdbObjects( lua_State* L)
|
|
{
|
|
try {
|
|
lua_register( L, "EgtExistsObj", LuaExistsObj) ;
|
|
lua_register( L, "EgtGetGroupObjs", LuaGetGroupObjs) ;
|
|
lua_register( L, "EgtGetFirstInGroup", LuaGetFirstInGroup) ;
|
|
lua_register( L, "EgtGetNext", LuaGetNext) ;
|
|
lua_register( L, "EgtGetLastInGroup", LuaGetLastInGroup) ;
|
|
lua_register( L, "EgtGetPrev", LuaGetPrev) ;
|
|
lua_register( L, "EgtGetFirstNameInGroup", LuaGetFirstNameInGroup) ;
|
|
lua_register( L, "EgtGetNextName", LuaGetNextName) ;
|
|
lua_register( L, "EgtCopy", LuaCopy) ;
|
|
lua_register( L, "EgtCopyGlob", LuaCopyGlob) ;
|
|
lua_register( L, "EgtRelocate", LuaRelocate) ;
|
|
lua_register( L, "EgtRelocateGlob", LuaRelocateGlob) ;
|
|
lua_register( L, "EgtErase", LuaErase) ;
|
|
}
|
|
catch ( ...) {
|
|
return false ;
|
|
}
|
|
return true ;
|
|
}
|