Files
EgtInterface/LUA_GeomDB.cpp
T
Dario Sassi 758245f4fc EgtInterface 1.6d6 :
- aggiunta EgtSaveObjToFile a API e Lua.
2015-04-30 20:42:52 +00:00

190 lines
5.5 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : LUA_General.cpp Data : 27.09.14 Versione : 1.5i5
// Contenuto : Funzioni generali per LUA.
//
//
//
// Modifiche : 27.09.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "API.h"
#include "LUA.h"
#include "LUA_Base.h"
#include "AuxTools.h"
#include "/EgtDev/Include/EInAPI.h"
#include "/EgtDev/Include/EGkLuaAux.h"
#include "/EgtDev/Include/EGnStringUtils.h"
using namespace std ;
//-------------------------------------------------------------------------------
static int
LuaSetDefaultMaterial( lua_State* L)
{
// un solo parametro, il colore
Color colDef ;
if ( ! LuaGetParam( L, 1, colDef))
return luaL_error( L, "Invalide first parameter") ;
LuaClearStack( L) ;
// imposto il colore di default
int vCol[4] ;
colDef.GetInt( vCol) ;
bool bOk = ( EgtSetDefaultMaterial( vCol) != FALSE) ;
// restituisco il risultato
LuaSetReturn( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaSetGridFrame( lua_State* L)
{
// 1 parametro : Frame
Frame3d frFrame ;
LuaCheckParam( L, 1, frFrame) ;
LuaClearStack( L) ;
// imposto il riferimento della Griglia (o CPlane)
bool bOk = ( EgtSetGridFrame( frFrame)) ;
// restituisco il risultato
LuaSetReturn( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaGetGridFrame( lua_State* L)
{
// 1 o nessun parametro : [nRefId]
int nRefId = GDB_ID_ROOT ;
if ( lua_gettop( L) >= 1)
LuaCheckParam( L, 1, nRefId)
LuaClearStack( L) ;
// recupero il riferimento della griglia
Frame3d frFrame ;
EgtGetGridFrame( nRefId, frFrame) ;
// restituisco il risultato
LuaSetReturn( L, frFrame) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaGetGridVersZ( lua_State* L)
{
// 1 o nessun parametro : [nRefId]
int nRefId = GDB_ID_ROOT ;
if ( lua_gettop( L) >= 1)
LuaCheckParam( L, 1, nRefId)
LuaClearStack( L) ;
// recupero il versore Z della griglia e lo restituisco
Vector3d vtVersZ ;
if ( EgtGetGridVersZ( nRefId, vtVersZ))
LuaSetReturn( L, vtVersZ) ;
else
LuaSetReturn( L) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaNewFile( lua_State* L)
{
// nessun parametro
LuaClearStack( L) ;
// nuovo progetto
bool bOk = ( EgtNewFile() != FALSE) ;
// restituisco il risultato
LuaSetReturn( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaOpenFile( lua_State* L)
{
// 1 parametro : path del file da aprire
string sFilePath ;
LuaCheckParam( L, 1, sFilePath)
LuaClearStack( L) ;
// apro il file
bool bOk = EgtOpenFile( sFilePath) ;
// restituisco il risultato
LuaSetReturn( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaInsertFile( lua_State* L)
{
// 1 parametro : path del file da importare
string sFilePath ;
LuaCheckParam( L, 1, sFilePath)
LuaClearStack( L) ;
// apro il file
bool bOk = EgtInsertFile( sFilePath) ;
// restituisco il risultato
LuaSetReturn( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaSaveFile( lua_State* L)
{
// 1 o 2 parametri : path del file [, flag]
string sFilePath ;
LuaCheckParam( L, 1, sFilePath)
int nFlag = GDB_SV_CMPTXT ;
LuaGetParam( L, 2, nFlag) ;
LuaClearStack( L) ;
// salvo il file
bool bOk = EgtSaveFile( sFilePath, nFlag) ;
// restituisco il risultato
LuaSetReturn( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
static int
LuaSaveObjToFile( lua_State* L)
{
// 2 o 3 parametri : nId, path del file [, flag]
int nId ;
LuaCheckParam( L, 1, nId)
string sFilePath ;
LuaCheckParam( L, 2, sFilePath)
int nFlag = GDB_SV_CMPTXT ;
LuaGetParam( L, 3, nFlag) ;
LuaClearStack( L) ;
// copio il gruppo nel file
bool bOk = EgtSaveObjToFile( nId, sFilePath, nFlag) ;
// restituisco il risultato
LuaSetReturn( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
bool
LuaInstallGeomDB( void)
{
bool bOk = true ;
bOk = bOk && LuaRegisterFunction( "EgtSetDefaultMaterial", LuaSetDefaultMaterial) ;
bOk = bOk && LuaRegisterFunction( "EgtSetGridFrame", LuaSetGridFrame) ;
bOk = bOk && LuaRegisterFunction( "EgtGetGridFrame", LuaGetGridFrame) ;
bOk = bOk && LuaRegisterFunction( "EgtGetGridVersZ", LuaGetGridVersZ) ;
bOk = bOk && LuaRegisterFunction( "EgtNewFile", LuaNewFile) ;
bOk = bOk && LuaRegisterFunction( "EgtOpenFile", LuaOpenFile) ;
bOk = bOk && LuaRegisterFunction( "EgtInsertFile", LuaInsertFile) ;
bOk = bOk && LuaRegisterFunction( "EgtSaveFile", LuaSaveFile) ;
bOk = bOk && LuaRegisterFunction( "EgtSaveObjToFile", LuaSaveObjToFile) ;
return bOk ;
}