79bbc3ec0e
- aggiunta gestione Assi di macchina per lettura e movimento - aggiunta gestione Teste di macchina per lettura e carico/scarico utensili.
338 lines
11 KiB
C++
338 lines
11 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2015-2015
|
|
//----------------------------------------------------------------------------
|
|
// File : MachineLua.cpp Data : 06.05.15 Versione : 1.6e3
|
|
// Contenuto : Implementazione gestione macchina : funzioni Lua.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 06.05.15 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "MachMgr.h"
|
|
#include "DllMain.h"
|
|
#include "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EGkGeomDB.h"
|
|
#include "/EgtDev/Include/EGkLuaAux.h"
|
|
#include "/EgtDev/Include/EGnStringUtils.h"
|
|
#include "/EgtDev/Include/EGnFileUtils.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
Machine* Machine::m_pMchLua = nullptr ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::LuaInit( const string& sMachineName)
|
|
{
|
|
// inizializzo l'interprete lua
|
|
if ( ! m_LuaMgr.Init())
|
|
return false ;
|
|
// carico le funzioni speciali
|
|
if ( ! LuaInstallEgtFunctions( m_LuaMgr))
|
|
return false ;
|
|
// recupero la versione di Lua
|
|
string sLua ;
|
|
if ( m_LuaMgr.GetVersion( sLua))
|
|
sLua += " machine interpreter started" ;
|
|
else
|
|
sLua = "Lua *.* machine interpreter started" ;
|
|
sLua += " (" + sMachineName + ")" ;
|
|
LOG_INFO( GetEMkLogger(), sLua.c_str())
|
|
// imposto il direttorio delle librerie
|
|
m_LuaMgr.SetLuaLibsDir( m_pMchMgr->m_sLuaLibsDir) ;
|
|
// carico la libreria standard
|
|
m_LuaMgr.Require( m_pMchMgr->m_sLuaLastRequire) ;
|
|
// registro le funzioni per lua
|
|
m_LuaMgr.RegisterFunction( "EmtGeneral", Machine::LuaEmtGeneral) ;
|
|
m_LuaMgr.RegisterFunction( "EmtBase", Machine::LuaEmtBase) ;
|
|
m_LuaMgr.RegisterFunction( "EmtTable", Machine::LuaEmtTable) ;
|
|
m_LuaMgr.RegisterFunction( "EmtAxis", Machine::LuaEmtAxis) ;
|
|
m_LuaMgr.RegisterFunction( "EmtHead", Machine::LuaEmtHead) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::LuaExit( void)
|
|
{
|
|
// chiudo lua ( se era aperto)
|
|
if ( m_LuaMgr.Exit()) {
|
|
string sLua = "Lua machine interpreter closed (" + m_sName + ")" ;
|
|
LOG_INFO( GetEMkLogger(), sLua.c_str())
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::LuaExecFile( const string& sFile)
|
|
{
|
|
// imposto contesto corretto
|
|
int nOldCtx = ExeGetCurrentContext() ;
|
|
if ( nOldCtx != m_pMchMgr->m_nContextId)
|
|
ExeSetCurrentContext( m_pMchMgr->m_nContextId) ;
|
|
// imposto l'oggetto corrente per Lua
|
|
m_pMchLua = this ;
|
|
// carico la macchina
|
|
bool bOk = m_LuaMgr.ExecFile( sFile) ;
|
|
// ripristino contesto originale
|
|
if ( nOldCtx != m_pMchMgr->m_nContextId)
|
|
ExeSetCurrentContext( nOldCtx) ;
|
|
return bOk ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
Machine::LuaEmtGeneral( lua_State* L)
|
|
{
|
|
ExeOutLog( "LuaEmtGeneral") ;
|
|
// Il parametro 1 deve essere una tabella
|
|
if ( ! lua_istable( L, 1))
|
|
return luaL_error( L, " Invalid Parameter, required a table") ;
|
|
// lettura campo 'File' dalla tabella
|
|
string sFile ;
|
|
LuaCheckTabFieldParam( L, 1, "File", sFile)
|
|
// lettura eventuale campo 'Offset' dalla tabella (default 0,0,0)
|
|
Vector3d vtOffset ;
|
|
LuaGetTabFieldParam( L, 1, "Offset", vtOffset) ;
|
|
LuaClearStack( L) ;
|
|
|
|
// verifico ci sia una macchina attiva
|
|
if ( m_pMchLua == nullptr)
|
|
return luaL_error( L, " Unknown Machine") ;
|
|
|
|
// carico la geometria della macchina
|
|
if ( ! m_pMchLua->LoadMachineGeometry( sFile, vtOffset))
|
|
return luaL_error( L, " Load Machine failed") ;
|
|
|
|
return 0 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
Machine::LuaEmtBase( lua_State* L)
|
|
{
|
|
ExeOutLog( "LuaEmtBase") ;
|
|
// Il parametro 1 deve essere una tabella
|
|
if ( ! lua_istable( L, 1))
|
|
return luaL_error( L, " Invalid Parameter, required a table") ;
|
|
// lettura campo 'Name' dalla tabella
|
|
string sName ;
|
|
LuaCheckTabFieldParam( L, 1, "Name", sName)
|
|
// lettura campo 'Geo' dalla tabella
|
|
string sGeo ;
|
|
LuaCheckTabFieldParam( L, 1, "Geo", sGeo)
|
|
LuaClearStack( L) ;
|
|
|
|
// verifico ci sia una macchina attiva
|
|
if ( m_pMchLua == nullptr)
|
|
return luaL_error( L, " Unknown Machine") ;
|
|
|
|
// carico i dati della base
|
|
if ( ! m_pMchLua->LoadMachineBase( sName, sGeo))
|
|
return luaL_error( L, " Load Machine Base failed") ;
|
|
|
|
return 0 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
Machine::LuaEmtTable( lua_State* L)
|
|
{
|
|
ExeOutLog( "LuaEmtTable") ;
|
|
// Il parametro 1 deve essere una tabella
|
|
if ( ! lua_istable( L, 1))
|
|
return luaL_error( L, " Invalid Parameter, required a table") ;
|
|
// lettura campo 'Name' dalla tabella
|
|
string sName ;
|
|
LuaCheckTabFieldParam( L, 1, "Name", sName)
|
|
// lettura campo 'Parent' dalla tabella
|
|
string sParent ;
|
|
LuaCheckTabFieldParam( L, 1, "Parent", sParent)
|
|
// lettura campo 'Type' dalla tabella
|
|
int nType ;
|
|
LuaCheckTabFieldParam( L, 1, "Type", nType)
|
|
// lettura campo 'Geo' dalla tabella
|
|
string sGeo ;
|
|
LuaCheckTabFieldParam( L, 1, "Geo", sGeo)
|
|
LuaClearStack( L) ;
|
|
|
|
// verifico ci sia una macchina attiva
|
|
if ( m_pMchLua == nullptr)
|
|
return luaL_error( L, " Unknown Machine") ;
|
|
|
|
// carico i dati della tavola
|
|
if ( ! m_pMchLua->LoadMachineTable( sName, sParent, nType, sGeo))
|
|
return luaL_error( L, " Load Machine Table failed") ;
|
|
|
|
return 0 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
Machine::LuaEmtAxis( lua_State* L)
|
|
{
|
|
ExeOutLog( "LuaEmtAxis") ;
|
|
// Il parametro 1 deve essere una tabella
|
|
if ( ! lua_istable( L, 1))
|
|
return luaL_error( L, " Invalid Parameter, required a table") ;
|
|
// lettura campo 'Name' dalla tabella
|
|
string sName ;
|
|
LuaCheckTabFieldParam( L, 1, "Name", sName)
|
|
// lettura campo 'Parent' dalla tabella
|
|
string sParent ;
|
|
LuaCheckTabFieldParam( L, 1, "Parent", sParent)
|
|
// lettura campo 'Type' dalla tabella
|
|
int nType ;
|
|
LuaCheckTabFieldParam( L, 1, "Type", nType)
|
|
// lettura campo 'Pos' dalla tabella
|
|
Point3d ptPos ;
|
|
LuaCheckTabFieldParam( L, 1, "Pos", ptPos)
|
|
// lettura campo 'Dir' dalla tabella
|
|
Vector3d vtDir ;
|
|
LuaCheckTabFieldParam( L, 1, "Dir", vtDir)
|
|
// lettura campo 'Stroke' dalla tabella
|
|
STROKE Stroke ;
|
|
LuaCheckTabFieldParam( L, 1, "Stroke", Stroke.v)
|
|
// lettura campo 'Geo' dalla tabella
|
|
string sGeo ;
|
|
LuaCheckTabFieldParam( L, 1, "Geo", sGeo)
|
|
// lettura eventuale campo 'Val' dalla tabella (default 0)
|
|
double dVal = 0 ;
|
|
LuaGetTabFieldParam( L, 1, "Val", dVal) ;
|
|
LuaClearStack( L) ;
|
|
|
|
// verifico ci sia una macchina attiva
|
|
if ( m_pMchLua == nullptr)
|
|
return luaL_error( L, " Unknown Machine") ;
|
|
|
|
// carico i dati dell'asse
|
|
if ( ! m_pMchLua->LoadMachineAxis( sName, sParent, nType, ptPos, vtDir, Stroke, sGeo, dVal))
|
|
return luaL_error( L, " Load Machine Axis failed") ;
|
|
|
|
return 0 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
Machine::LuaEmtHead( lua_State* L)
|
|
{
|
|
ExeOutLog( "LuaEmtHead") ;
|
|
// Il parametro 1 deve essere una tabella
|
|
if ( ! lua_istable( L, 1))
|
|
return luaL_error( L, " Invalid Parameter, required a table") ;
|
|
// lettura campo 'Type' dalla tabella
|
|
int nType ;
|
|
LuaCheckTabFieldParam( L, 1, "Type", nType)
|
|
|
|
// Procedo alla lettura a seconda del tipo
|
|
if ( nType == MCH_HT_STD)
|
|
return LuaEmtStdHead( L) ;
|
|
else if ( nType == MCH_HT_MULTI)
|
|
return LuaEmtMultiHead( L) ;
|
|
else
|
|
return luaL_error( L, " Head type unknown") ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
Machine::LuaEmtStdHead( lua_State* L)
|
|
{
|
|
ExeOutLog( " Standard Head") ;
|
|
// Il parametro 1 deve essere una tabella
|
|
if ( ! lua_istable( L, 1))
|
|
return luaL_error( L, " Invalid Parameter, required a table") ;
|
|
// lettura campo 'Name' dalla tabella
|
|
string sName ;
|
|
LuaCheckTabFieldParam( L, 1, "Name", sName)
|
|
// lettura campo 'Parent' dalla tabella
|
|
string sParent ;
|
|
LuaCheckTabFieldParam( L, 1, "Parent", sParent)
|
|
// lettura campo 'HSet' dalla tabella
|
|
string sHSet ;
|
|
LuaCheckTabFieldParam( L, 1, "HSet", sHSet)
|
|
// lettura campo 'Pos' dalla tabella
|
|
Point3d ptPos ;
|
|
LuaCheckTabFieldParam( L, 1, "Pos", ptPos)
|
|
// lettura campo 'TDir' dalla tabella
|
|
Vector3d vtTDir ;
|
|
LuaCheckTabFieldParam( L, 1, "TDir", vtTDir)
|
|
// lettura campo 'ADir' dalla tabella
|
|
Vector3d vtADir ;
|
|
LuaCheckTabFieldParam( L, 1, "ADir", vtADir)
|
|
// lettura campo 'Geo' dalla tabella
|
|
string sGeo ;
|
|
LuaCheckTabFieldParam( L, 1, "Geo", sGeo)
|
|
LuaClearStack( L) ;
|
|
|
|
// verifico ci sia una macchina attiva
|
|
if ( m_pMchLua == nullptr)
|
|
return luaL_error( L, " Unknown Machine") ;
|
|
|
|
// carico i dati della testa standard
|
|
if ( ! m_pMchLua->LoadMachineStdHead( sName, sParent, sHSet, ptPos, vtTDir, vtADir, sGeo))
|
|
return luaL_error( L, " Load Machine Standard Head failed") ;
|
|
|
|
return 0 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
Machine::LuaEmtMultiHead( lua_State* L)
|
|
{
|
|
ExeOutLog( " Multiple Head") ;
|
|
// Il parametro 1 deve essere una tabella
|
|
if ( ! lua_istable( L, 1))
|
|
return luaL_error( L, " Invalid Parameter, required a table") ;
|
|
// lettura campo 'Name' dalla tabella
|
|
string sName ;
|
|
LuaCheckTabFieldParam( L, 1, "Name", sName)
|
|
// lettura campo 'Parent' dalla tabella
|
|
string sParent ;
|
|
LuaCheckTabFieldParam( L, 1, "Parent", sParent)
|
|
// lettura campo 'HSet' dalla tabella
|
|
string sHSet ;
|
|
LuaCheckTabFieldParam( L, 1, "HSet", sHSet)
|
|
// lettura campo 'ExitNbr' dalla tabella
|
|
int nExitNbr ;
|
|
LuaCheckTabFieldParam( L, 1, "ExitNbr", nExitNbr)
|
|
// lettura campi 'PosN' e 'TDirN' per ogni uscita dalla tabella
|
|
MUEXITVECTOR vMuExit ;
|
|
vMuExit.reserve( nExitNbr) ;
|
|
for ( int i = 0 ; i < nExitNbr ; ++ i) {
|
|
// lettura
|
|
string sPos = "Pos" + ToString( i + 1) ;
|
|
Point3d ptPos ;
|
|
LuaCheckTabFieldParam( L, 1, sPos.c_str(), ptPos)
|
|
string sTDir = "TDir" + ToString( i + 1) ;
|
|
Vector3d vtTDir ;
|
|
LuaCheckTabFieldParam( L, 1, sTDir.c_str(), vtTDir)
|
|
// inserimento nell'array
|
|
vMuExit.emplace_back( ptPos, vtTDir) ;
|
|
}
|
|
// lettura campo 'ADir' dalla tabella
|
|
Vector3d vtADir ;
|
|
LuaCheckTabFieldParam( L, 1, "ADir", vtADir)
|
|
// lettura campo 'Geo' dalla tabella
|
|
string sGeo ;
|
|
LuaCheckTabFieldParam( L, 1, "Geo", sGeo)
|
|
LuaClearStack( L) ;
|
|
|
|
// verifico ci sia una macchina attiva
|
|
if ( m_pMchLua == nullptr)
|
|
return luaL_error( L, " Unknown Machine") ;
|
|
|
|
// carico i dati della testa multipla
|
|
if ( ! m_pMchLua->LoadMachineMultiHead( sName, sParent, sHSet, vMuExit, vtADir, sGeo))
|
|
return luaL_error( L, " Load Machine Standard Head failed") ;
|
|
|
|
return 0 ;
|
|
}
|