EgtMachKernel 1.6e4 :

- aggiunta gestione Assi di macchina per lettura e movimento
- aggiunta gestione Teste di macchina per lettura e carico/scarico utensili.
This commit is contained in:
Dario Sassi
2015-05-11 21:02:55 +00:00
parent 685966ac11
commit 79bbc3ec0e
14 changed files with 1134 additions and 89 deletions
BIN
View File
Binary file not shown.
+3
View File
@@ -206,6 +206,9 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
<ItemGroup>
<ClCompile Include="EMkDllMain.cpp" />
<ClCompile Include="Machine.cpp" />
<ClCompile Include="MachineAxes.cpp" />
<ClCompile Include="MachineLua.cpp" />
<ClCompile Include="MachineHeads.cpp" />
<ClCompile Include="MachMgrBasic.cpp" />
<ClCompile Include="MachMgrMachGroups.cpp" />
<ClCompile Include="MachMgrMachines.cpp" />
+9
View File
@@ -45,6 +45,15 @@
<ClCompile Include="Machine.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MachineLua.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MachineHeads.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MachineAxes.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="DllMain.h">
+31
View File
@@ -38,6 +38,37 @@ const std::string MACH_RAW_SOLID = "RawSolid" ;
// Nome del punto che rappresenta il centro del grezzo
const std::string MACH_RAW_CENTER = "RawCenter" ;
//----------------------------------------------------------------------------
// Nome sottodirettorio degli utensili
const std::string TOOLS_DIR = "Tools" ;
//----------------------------------------------------------------------------
// Minimo spessore del grezzo
const double RAW_MIN_H = 1 ;
//----------------------------------------------------------------------------
// Tipo di tavola della macchina
enum MchTabType { MCH_TT_NONE = 0,
MCH_TT_FLAT = 1} ;
//----------------------------------------------------------------------------
// Tipo di assi della macchina
enum MchAxisType { MCH_AT_NONE = 0,
MCH_AT_LINEAR = 1,
MCH_AT_ROTARY = 2} ;
//----------------------------------------------------------------------------
// Tipo di testa della macchina
enum MchHeadType { MCH_HT_NONE = 0,
MCH_HT_STD = 1,
MCH_HT_MULTI = 2} ;
//----------------------------------------------------------------------------
// Identificativi del tipo di oggetto negli info dei gruppi macchina
const char MCH_AXIS = 'A' ;
const char MCH_TAB = 'T' ;
const char MCH_HEAD = 'H' ;
//----------------------------------------------------------------------------
// Lunghezza vettore di movimento degli assi macchina
const double AXIS_LEN = 100 ;
+13 -1
View File
@@ -36,10 +36,13 @@ struct MachGrp {
//----------------------------------------------------------------------------
class MachMgr : public IMachMgr
{
friend class Machine ;
public :
// Basic
virtual ~MachMgr( void) ;
virtual bool Init( int nContextId, IGeomDB* pGeomDB, const std::string& sMachinesDir) ;
virtual bool Init( const std::string& sMachinesDir, IGeomDB* pGeomDB,
int nContextId, const std::string& sLuaLibsDir, const std::string& sLuaLastRequire) ;
virtual bool Update( void) ;
virtual bool Insert( int nInsGrp) ;
// MachGroups
@@ -74,6 +77,13 @@ class MachMgr : public IMachMgr
virtual bool RemovePartFromRawPart( int nPartId) ;
virtual bool TranslatePartInRawPart( int nPartId, const Vector3d& vtMove) ;
virtual bool RotatePartInRawPart( int nPartId, const Vector3d& vtAx, double dAngRotDeg) ;
// Machine
virtual bool SetAxisPos( const std::string& sAxis, double dVal) ;
virtual bool GetAxisPos( const std::string& sAxis, double& dVal) ;
virtual bool GetAxisHomePos( const std::string& sAxis, double& dHomeVal) ;
virtual bool ResetAxisPos( const std::string& sAxis) ;
virtual bool LoadTool( const std::string& sHead, int nExit, const std::string& sTool) ;
virtual bool ResetHeadSet( const std::string& sHead) ;
public :
MachMgr( void) ;
@@ -126,6 +136,8 @@ class MachMgr : public IMachMgr
int m_nContextId ; // 1-based
IGeomDB* m_pGeomDB ;
std::string m_sMachinesDir ;
std::string m_sLuaLibsDir ;
std::string m_sLuaLastRequire ;
int m_nMachBaseId ;
int m_nMachAuxId ;
int m_nCurrMGrpId ;
+4 -1
View File
@@ -80,11 +80,14 @@ MachMgr::Clear( void)
//----------------------------------------------------------------------------
bool
MachMgr::Init( int nContextId, IGeomDB* pGeomDB, const string& sMachinesDir)
MachMgr::Init( const string& sMachinesDir, IGeomDB* pGeomDB,
int nContextId, const string& sLuaLibsDir, const string& sLuaLastRequire)
{
m_nContextId = nContextId ;
m_pGeomDB = pGeomDB ;
m_sMachinesDir = sMachinesDir ;
m_sLuaLibsDir = sLuaLibsDir ;
m_sLuaLastRequire = sLuaLastRequire ;
m_nMachBaseId = GDB_ID_NULL ;
m_nMachAuxId = GDB_ID_NULL ;
m_nCurrMGrpId = GDB_ID_NULL ;
+62 -46
View File
@@ -40,32 +40,11 @@ MachMgr::LoadMachine( const string& sMachineName)
if ( IsNull( pMch))
return false ;
// tento di caricarla
string sMachineDir = m_sMachinesDir + "\\" + sMachineName ;
if ( pMch->Init( m_nContextId, m_pGeomDB, m_nMachAuxId, sMachineDir, sMachineName)) {
if ( pMch->Init( sMachineName, this)) {
m_vMachines.push_back( Release( pMch)) ;
return true ;
}
return false ;
#if 0
// verifico esistenza macchina
string sMachineDir = m_sMachinesDir + "\\" + sMachineName ;
string sMachineMde = sMachineDir + "\\" + sMachineName + ".Mde" ;
if ( ! ExistsFile( sMachineMde))
return false ;
// carico la macchina
if ( ! CreateMachAux())
return false ;
// creo il gruppo per la macchina
int nId = m_pGeomDB->InsertGroup( GDB_ID_NULL, m_nMachAuxId, GDB_LAST_SON, GLOB_FRM) ;
if ( nId == GDB_ID_NULL)
return false ;
// imposto nome del gruppo
m_pGeomDB->SetName( nId, sMachineName) ;
// inserisco la geometria della macchina !!! PROVVISORIO !!!
string sMachineNge = sMachineDir + "\\" + sMachineName + ".Nge" ;
return m_pGeomDB->Load( sMachineNge, nId) ;
#endif
}
//----------------------------------------------------------------------------
@@ -79,29 +58,6 @@ MachMgr::GetMachine( const string& sMachineName) const
return int( i) ;
}
return - 1 ;
#if 0
// verifico validità del nome
if ( ! IsValidName( sMachineName))
return GDB_ID_NULL ;
// se non c'è il gruppo ausiliario per le macchine, non ci può essere la macchina
if ( ! VerifyMachAux())
return GDB_ID_NULL ;
// recupero l'identificativo del gruppo con il nome indicato
PtrOwner<IGdbIterator> pIter( CreateGdbIterator( m_pGeomDB)) ;
if ( IsNull( pIter))
return GDB_ID_NULL ;
bool bIter = pIter->GoToFirstGroupInGroup( m_nMachAuxId) ;
while( bIter) {
// verifico il nome
string sMGroupName ;
if ( pIter->GetName( sMGroupName) && sMGroupName == sMachineName)
return pIter->GetId() ;
// passo al successivo
bIter = pIter->GoToNextGroup() ;
}
return GDB_ID_NULL ;
#endif
}
//----------------------------------------------------------------------------
@@ -111,5 +67,65 @@ MachMgr::GetCurrMGeoId( void) const
if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) ||
m_vMachines[m_nCurrMch] == nullptr)
return GDB_ID_NULL ;
return ( m_vMachines[m_nCurrMch]->GetMGeoId()) ;
return m_vMachines[m_nCurrMch]->GetMGeoId() ;
}
//----------------------------------------------------------------------------
bool
MachMgr::SetAxisPos( const string& sAxis, double dVal)
{
if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) ||
m_vMachines[m_nCurrMch] == nullptr)
return GDB_ID_NULL ;
return m_vMachines[m_nCurrMch]->SetAxisPos( sAxis, dVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::GetAxisPos( const string& sAxis, double& dVal)
{
if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) ||
m_vMachines[m_nCurrMch] == nullptr)
return GDB_ID_NULL ;
return m_vMachines[m_nCurrMch]->GetAxisPos( sAxis, dVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::GetAxisHomePos( const string& sAxis, double& dHomeVal)
{
if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) ||
m_vMachines[m_nCurrMch] == nullptr)
return GDB_ID_NULL ;
return m_vMachines[m_nCurrMch]->GetAxisHomePos( sAxis, dHomeVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::ResetAxisPos( const string& sAxis)
{
if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) ||
m_vMachines[m_nCurrMch] == nullptr)
return GDB_ID_NULL ;
return m_vMachines[m_nCurrMch]->ResetAxisPos( sAxis) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::LoadTool( const string& sHead, int nExit, const string& sTool)
{
if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) ||
m_vMachines[m_nCurrMch] == nullptr)
return false ;
return m_vMachines[m_nCurrMch]->LoadTool( sHead, nExit, sTool) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::ResetHeadSet( const string& sHead)
{
if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) ||
m_vMachines[m_nCurrMch] == nullptr)
return false ;
return m_vMachines[m_nCurrMch]->ResetHeadSet( sHead) ;
}
+7 -7
View File
@@ -374,16 +374,16 @@ MachMgr::MoveToCornerRawPart( int nRawId, const Point3d& ptP, int nFlag)
// calcolo il movimento necessario
Vector3d vtMove ;
switch ( nFlag) {
case RPCR_TL :
case MCH_CR_TL :
vtMove = ptP - Point3d( b3Raw.GetMin().x, b3Raw.GetMax().y, b3Raw.GetMin().z) ;
break ;
case RPCR_TR :
case MCH_CR_TR :
vtMove = ptP - Point3d( b3Raw.GetMax().x, b3Raw.GetMax().y, b3Raw.GetMin().z) ;
break ;
default : // RPCP_BL
vtMove = ptP - b3Raw.GetMin() ;
break ;
case RPCR_BR :
case MCH_CR_BR :
vtMove = ptP - Point3d( b3Raw.GetMax().x, b3Raw.GetMin().y, b3Raw.GetMin().z) ;
break ;
}
@@ -410,19 +410,19 @@ MachMgr::MoveToCenterRawPart( int nRawId, const Point3d& ptP, int nFlag)
// calcolo il movimento necessario
Vector3d vtMove ;
switch ( nFlag) {
case RPCE_TC :
case MCH_CE_TC :
vtMove = ptP - Point3d( ptCen.x, b3Raw.GetMax().y, ptCen.z) ;
break ;
default : // RPCE_ML
vtMove = ptP - Point3d( b3Raw.GetMin().x, ptCen.y, ptCen.z) ;
break ;
case RPCE_MR :
case MCH_CE_MR :
vtMove = ptP - Point3d( b3Raw.GetMax().x, ptCen.y, ptCen.z) ;
break ;
case RPCE_BC :
case MCH_CE_BC :
vtMove = ptP - Point3d( ptCen.x, b3Raw.GetMin().y, ptCen.z) ;
break ;
case RPCE_MC :
case MCH_CE_MC :
vtMove = ptP - Point3d( ptCen.x, ptCen.y, b3Raw.GetMin().z) ;
break ;
}
+400 -26
View File
@@ -13,18 +13,20 @@
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "Machine.h"
#include "MachMgr.h"
#include "DllMain.h"
#include "/EgtDev/Include/EGkGeomDB.h"
#include "/EgtDev/Include/EGkGeoVector3d.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EGnFileUtils.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
using namespace std ;
//----------------------------------------------------------------------------
Machine::Machine( void)
{
m_nContextId = 0 ;
m_pGeomDB = nullptr ;
m_pMchMgr = nullptr ;
m_nGroupId = GDB_ID_NULL ;
}
@@ -38,47 +40,419 @@ Machine::~Machine( void)
void
Machine::Clear( void)
{
// cancellazione eventuale gruppo geometrico associato
if ( m_pGeomDB != nullptr && m_nGroupId != GDB_ID_NULL)
m_pGeomDB->Erase( m_nGroupId) ;
// cancellazione eventuali gruppi geometrici associati
if ( m_pMchMgr != nullptr && m_pMchMgr->m_pGeomDB != nullptr) {
if ( m_nGroupId != GDB_ID_NULL)
m_pMchMgr->m_pGeomDB->Erase( m_nGroupId) ;
if ( m_nTempGroupId != GDB_ID_NULL)
m_pMchMgr->m_pGeomDB->Erase( m_nTempGroupId) ;
}
// pulizia interprete lua di macchina
LuaExit() ;
// reset membri
m_nContextId = 0 ;
m_pGeomDB = nullptr ;
m_nGroupId = GDB_ID_NULL ;
m_pMchMgr = nullptr ;
m_sName.clear() ;
m_sMachineDir.clear() ;
m_nGroupId = GDB_ID_NULL ;
m_nTempGroupId = GDB_ID_NULL ;
m_mapGroups.clear() ;
m_mapGroups.rehash( 20) ;
}
//----------------------------------------------------------------------------
bool
Machine::Init( int nContextId, IGeomDB* pGeomDB, int nMachAuxId,
const string& sMachineDir, const string& sMachineName)
Machine::Init( const std::string& sMachineName, MachMgr* pMchMgr)
{
// pulisco
Clear() ;
// verifico ambiente geometrico
if ( nContextId == 0 || pGeomDB == nullptr)
// verifico ambiente
if ( pMchMgr == nullptr || pMchMgr->m_nContextId == 0 || pMchMgr->m_pGeomDB == nullptr)
return false ;
// verifico esistenza macchina
string sMachineMde = sMachineDir + "\\" + sMachineName + ".Mde" ;
if ( ! ExistsFile( sMachineMde))
m_pMchMgr = pMchMgr ;
// verifico direttorio dati macchina
m_sMachineDir = pMchMgr->m_sMachinesDir + "\\" + sMachineName ;
if ( ! ExistsDirectory( m_sMachineDir))
return false ;
// creo il gruppo per la macchina
int nId = pGeomDB->InsertGroup( GDB_ID_NULL, nMachAuxId, GDB_LAST_SON, GLOB_FRM) ;
int nId = pMchMgr->m_pGeomDB->InsertGroup( GDB_ID_NULL, pMchMgr->m_nMachAuxId, GDB_LAST_SON, GLOB_FRM) ;
if ( nId == GDB_ID_NULL)
return false ;
// imposto nome del gruppo
pGeomDB->SetName( nId, sMachineName) ;
// inserisco la geometria della macchina !!! PROVVISORIO !!!
string sMachineNge = sMachineDir + "\\" + sMachineName + ".Nge" ;
if ( ! pGeomDB->Load( sMachineNge, nId)) {
pGeomDB->Erase( nId) ;
pMchMgr->m_pGeomDB->SetName( nId, sMachineName) ;
// carico l'interprete lua dedicato alla macchina
if ( ! LuaInit( sMachineName)) {
pMchMgr->m_pGeomDB->Erase( nId) ;
return false ;
}
// salvo i dati
m_nContextId = nContextId ;
m_pGeomDB = pGeomDB ;
m_nGroupId = nId ;
m_sMachineDir = sMachineDir ;
m_sName = sMachineName ;
// carico la macchina {
string sMachineMde = m_sMachineDir + "\\" + sMachineName + ".Mde" ;
bool bOk = LuaExecFile( sMachineMde) ;
// cancello il gruppo temporaneo
pMchMgr->m_pGeomDB->Erase( m_nTempGroupId) ;
m_nTempGroupId = GDB_ID_NULL ;
// in caso di errore, cancello tutta la geometria
if ( ! bOk) {
pMchMgr->m_pGeomDB->Erase( m_nGroupId) ;
pMchMgr->m_pGeomDB->Erase( m_nTempGroupId) ;
m_nGroupId = GDB_ID_NULL ;
m_nTempGroupId = GDB_ID_NULL ;
m_sName.clear() ;
m_sMachineDir.clear() ;
}
return bOk ;
}
//----------------------------------------------------------------------------
bool
Machine::LoadMachineGeometry( const string& sMGeoName, const Vector3d& vtOffset)
{
// creo un sotto gruppo temporaneo in cui caricare la macchina
m_nTempGroupId = m_pMchMgr->m_pGeomDB->AddGroup( GDB_ID_NULL, m_pMchMgr->m_nMachAuxId, GLOB_FRM) ;
if ( m_nTempGroupId == GDB_ID_NULL)
return false ;
// carico la macchina
string sMachineNge = m_sMachineDir + "\\" + sMGeoName ;
if ( ! m_pMchMgr->m_pGeomDB->Load( sMachineNge, m_nTempGroupId))
return false ;
// applico offset
return m_pMchMgr->m_pGeomDB->TranslateGlob( m_nTempGroupId, vtOffset) ;
}
//----------------------------------------------------------------------------
bool
Machine::LoadMachineBase( const string& sName, const string& sGeo)
{
// recupero pezzo e layer della geometria originale della base
string sPart, sLay ;
Split( sGeo, "/", true, sPart, sLay) ;
// cerco il gruppo nella geometria originale
int nPart = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
int nLay = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
if ( nLay == GDB_ID_NULL)
return false ;
// lo sposto nella radice della macchina
if ( ! m_pMchMgr->m_pGeomDB->RelocateGlob( nLay, m_nGroupId, GDB_FIRST_SON))
return false ;
// gli assegno il nome
m_pMchMgr->m_pGeomDB->SetName( nLay, sName) ;
// lo inserisco nel dizionario dei gruppi della macchina
return m_mapGroups.emplace( sName, nLay).second ;
}
//----------------------------------------------------------------------------
bool
Machine::LoadMachineTable( const string& sName, const string& sParent, int nType, const string& sGeo)
{
// recupero pezzo e layer della geometria originale della tavola
string sPart, sLay ;
Split( sGeo, "/", true, sPart, sLay) ;
// cerco il gruppo nella geometria originale
int nPart = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
int nLay = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
if ( nLay == GDB_ID_NULL)
return false ;
// cerco il gruppo padre per spostarvelo
int nParentId = GetGroup( sParent) ;
if ( nParentId == GDB_ID_NULL ||
! m_pMchMgr->m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON))
return false ;
// gli assegno il nome
m_pMchMgr->m_pGeomDB->SetName( nLay, sName) ;
// gli assegno il tipo
string sInfo = MCH_TAB + ToString( nType) ;
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "Type", sInfo) ;
// lo inserisco nel dizionario dei gruppi della macchina
return m_mapGroups.emplace( sName, nLay).second ;
}
//----------------------------------------------------------------------------
bool
Machine::LoadMachineAxis( const string& sName, const string& sParent, int nType,
const Point3d& ptPos, const Vector3d& vtDir,
const STROKE& Stroke, const string& sGeo, double dVal)
{
// recupero pezzo e layer della geometria originale dell'asse
string sPart, sLay ;
Split( sGeo, "/", true, sPart, sLay) ;
// cerco il gruppo nella geometria originale
int nPart = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
int nLay = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
if ( nLay == GDB_ID_NULL)
return false ;
// cerco il gruppo padre per spostarvelo
int nParentId = GetGroup( sParent) ;
if ( nParentId == GDB_ID_NULL ||
! m_pMchMgr->m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON))
return false ;
// verifico che il valore sia nei limiti di corsa
if ( dVal < Stroke.Min || dVal > Stroke.Max)
return false ;
// gli assegno il nome
m_pMchMgr->m_pGeomDB->SetName( nLay, sName) ;
// gli assegno il tipo
string sInfo = MCH_AXIS + ToString( nType) ;
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "Type", sInfo) ;
// gli assegno la posizione
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "Pos", ptPos) ;
// gli assegno la direzione
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "Dir", vtDir) ;
// gli assegno i limiti di corsa
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "Stroke", ToString( Stroke.v)) ;
// gli assegno il valore iniziale di home
if ( ! m_pMchMgr->m_pGeomDB->SetInfo( nLay, "HVal", dVal))
return false ;
// gli assegno il valore corrente
if ( ! m_pMchMgr->m_pGeomDB->SetInfo( nLay, "Val", dVal))
return false ;
// inserisco il vettore rappresentativo dell'asse
if ( ! AddAxisVector( nLay, ptPos, vtDir, sName))
return false ;
// lo inserisco nel dizionario dei gruppi della macchina
return m_mapGroups.emplace( sName, nLay).second ;
}
//----------------------------------------------------------------------------
bool
Machine::AddAxisVector( int nLay, const Point3d& ptPos, const Vector3d& vtDir, const string& sName)
{
// riferimento globale del gruppo asse
Frame3d frFrame ;
m_pMchMgr->m_pGeomDB->GetGroupGlobFrame( nLay, frFrame) ;
// punto base e vettore in locale
Point3d ptBase = ptPos ;
ptBase.ToLoc( frFrame) ;
Vector3d vtAxis = vtDir ;
if ( ! vtAxis.Normalize())
return false ;
vtAxis *= AXIS_LEN ;
vtAxis.ToLoc( frFrame) ;
// vettore geometrico
PtrOwner<IGeoVector3d> pGeoVct( CreateGeoVector3d()) ;
if ( IsNull( pGeoVct) || ! pGeoVct->Set( vtAxis, ptBase))
return false ;
// lo inserisco al primo posto nel gruppo
int nId = m_pMchMgr->m_pGeomDB->InsertGeoObj( GDB_ID_NULL, nLay, GDB_FIRST_SON, Release( pGeoVct)) ;
if ( nId == GDB_ID_NULL)
return false ;
// gli assegno il nome di axis
if ( ! m_pMchMgr->m_pGeomDB->SetName( nId, sName))
return false ;
// gli assegno il colore blu
if ( ! m_pMchMgr->m_pGeomDB->SetMaterial( nId, BLUE))
return false ;
// lo nascondo
if ( ! m_pMchMgr->m_pGeomDB->SetStatus( nId, GDB_ST_OFF))
return false ;
return true ;
}
}
//----------------------------------------------------------------------------
bool
Machine::LoadMachineStdHead( const string& sName, const string& sParent, const std::string& sHSet,
const Point3d& ptPos, const Vector3d& vtTDir,
const Vector3d& vtADir, const string& sGeo)
{
// recupero pezzo e layer della geometria originale dell'asse
string sPart, sLay ;
Split( sGeo, "/", true, sPart, sLay) ;
// cerco il gruppo nella geometria originale
int nPart = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
int nLay = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
if ( nLay == GDB_ID_NULL)
return false ;
// cerco il gruppo padre per spostarvelo
int nParentId = GetGroup( sParent) ;
if ( nParentId == GDB_ID_NULL ||
! m_pMchMgr->m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON))
return false ;
// sistemo lo stato di visualizzazione
bool bShow = ( sHSet == sName) ;
m_pMchMgr->m_pGeomDB->SetStatus( nLay, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ;
// gli assegno il nome
m_pMchMgr->m_pGeomDB->SetName( nLay, sName) ;
// gli assegno l'insieme di teste e aggiorno il capostipite
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "HSet", sHSet) ;
if ( ! AddHeadToSet( sHSet, sName))
return false ;
// gli assegno il tipo
string sInfo = MCH_HEAD + ToString( MCH_HT_STD) ;
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "Type", sInfo) ;
// gli assegno la posizione
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "Pos", ptPos) ;
// gli assegno la direzione utensile
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "TDir", vtTDir) ;
// gli assegno la direzione ausiliaria
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "ADir", vtADir) ;
// trasformazione del riferimento di uscita in gruppo di uscita
if ( ! CreateExitGroups( nLay, 1))
return false ;
// lo inserisco nel dizionario dei gruppi della macchina
return m_mapGroups.emplace( sName, nLay).second ;
}
//----------------------------------------------------------------------------
bool
Machine::LoadMachineMultiHead( const string& sName, const string& sParent, const std::string& sHSet,
MUEXITVECTOR vMuExit,
const Vector3d& vtADir, const string& sGeo)
{
// recupero pezzo e layer della geometria originale dell'asse
string sPart, sLay ;
Split( sGeo, "/", true, sPart, sLay) ;
// cerco il gruppo nella geometria originale
int nPart = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ;
int nLay = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ;
if ( nLay == GDB_ID_NULL)
return false ;
// cerco il gruppo padre per spostarvelo
int nParentId = GetGroup( sParent) ;
if ( nParentId == GDB_ID_NULL ||
! m_pMchMgr->m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON))
return false ;
// sistemo lo stato di visualizzazione
bool bShow = ( sHSet == sName) ;
m_pMchMgr->m_pGeomDB->SetStatus( nLay, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ;
// gli assegno il nome
m_pMchMgr->m_pGeomDB->SetName( nLay, sName) ;
// gli assegno il tipo
string sInfo = MCH_HEAD + ToString( MCH_HT_MULTI) ;
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "Type", sInfo) ;
// gli assegno l'insieme teste e aggiorno il capostipite
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "HSet", sHSet) ;
if ( ! AddHeadToSet( sHSet, sName))
return false ;
// gli assegno le posizioni e direzioni delle uscite
for ( int i = 0 ; i < int( vMuExit.size()) ; ++ i) {
string sPos = "Pos" + ToString( i + 1) ;
m_pMchMgr->m_pGeomDB->SetInfo( nLay, sPos, vMuExit[i].ptPos) ;
string sTDir = "TDir" + ToString( i + 1) ;
m_pMchMgr->m_pGeomDB->SetInfo( nLay, sTDir, vMuExit[i].vtTDir) ;
}
// gli assegno la direzione ausiliaria
m_pMchMgr->m_pGeomDB->SetInfo( nLay, "ADir", vtADir) ;
// trasformazione dei riferimenti di uscita in gruppi di uscita
if ( ! CreateExitGroups( nLay, int( vMuExit.size())))
return false ;
// lo inserisco nel dizionario dei gruppi della macchina
return m_mapGroups.emplace( sName, nLay).second ;
}
//----------------------------------------------------------------------------
int
Machine::GetGroup( const string& sGroup)
{
STRINT_UMAP::const_iterator Iter = m_mapGroups.find( sGroup) ;
return (( Iter != m_mapGroups.end()) ? Iter->second : GDB_ID_NULL) ;
}
//----------------------------------------------------------------------------
bool
Machine::IsAxisGroup( int nGroup)
{
string sType ;
return ( m_pMchMgr->m_pGeomDB->GetInfo( nGroup, "Type", sType) && sType[0] == MCH_AXIS) ;
}
//----------------------------------------------------------------------------
bool
Machine::IsTableGroup( int nGroup)
{
string sType ;
return ( m_pMchMgr->m_pGeomDB->GetInfo( nGroup, "Type", sType) && sType[0] == MCH_TAB) ;
}
//----------------------------------------------------------------------------
bool
Machine::IsHeadGroup( int nGroup)
{
string sType ;
return ( m_pMchMgr->m_pGeomDB->GetInfo( nGroup, "Type", sType) && sType[0] == MCH_HEAD) ;
}
//----------------------------------------------------------------------------
bool
Machine::AddHeadToSet( const string& sHSet, const string& sName)
{
// se il capo-insieme coincide con la testa, non devo fare alcunchè
if ( sHSet == sName)
return true ;
// recupero le info della testa capo-insieme
int nHGroupId = GetGroup( sHSet) ;
if ( nHGroupId == GDB_ID_NULL)
return false ;
STRVECTOR vsHSet ;
if ( ! m_pMchMgr->m_pGeomDB->GetInfo( nHGroupId, "HSet", vsHSet))
return false ;
// se già presente non devo fare alcunchè, altrimenti lo aggiungo
if ( find( vsHSet.begin(), vsHSet.end(), sName) != vsHSet.end())
return true ;
vsHSet.emplace_back( sName) ;
return m_pMchMgr->m_pGeomDB->SetInfo( nHGroupId, "HSet", vsHSet) ;
}
//----------------------------------------------------------------------------
bool
Machine::GetHSet( const string& sHead, STRVECTOR& vsHSet)
{
// recupero l'indice della testa
int nHead = GetGroup( sHead) ;
if ( ! IsHeadGroup( nHead))
return false ;
// recupero la stringa dell'insieme di teste
if ( ! m_pMchMgr->m_pGeomDB->GetInfo( nHead, "HSet", vsHSet))
return false ;
// se il primo membro coincide con la testa, allora è già l'insieme di teste
if ( vsHSet[0] == sHead)
return true ;
// altrimenti cerco l'insieme della prima testa
return GetHSet( vsHSet[0], vsHSet) ;
}
//----------------------------------------------------------------------------
bool
Machine::EnableHeadInSet( const string& sHead)
{
// recupero l'insieme di teste
STRVECTOR vsHSet ;
if ( ! GetHSet( sHead, vsHSet))
return false ;
// spengo tutte le teste tranne questa
for ( size_t i = 0 ; i < vsHSet.size() ; ++ i) {
int nH = GetGroup( vsHSet[i]) ;
bool bShow = ( vsHSet[i] == sHead) ;
m_pMchMgr->m_pGeomDB->SetStatus( nH, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
Machine::CreateExitGroups( int nLay, int nExitNbr)
{
// ciclo sulle uscite
for ( int i = 1 ; i <= nExitNbr ; ++ i) {
string sName = "T" + ToString( i) ;
// se trovo riferimento per uscita, lo sostituisco con gruppo equivalente
int nT = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nLay, sName) ;
if ( nT != GDB_ID_NULL && m_pMchMgr->m_pGeomDB->GetGeoType( nT) == GEO_FRAME3D) {
const Frame3d& frFrame = GetGeoFrame3d( m_pMchMgr->m_pGeomDB->GetGeoObj( nT))->GetFrame() ;
int nGT = m_pMchMgr->m_pGeomDB->InsertGroup( GDB_ID_NULL, nT, GDB_AFTER, frFrame) ;
if ( nGT == GDB_ID_NULL) {
string sOut = "Error inserting group " + sName ;
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
return false ;
}
m_pMchMgr->m_pGeomDB->Erase( nT) ;
m_pMchMgr->m_pGeomDB->SetName( nGT, sName) ;
}
else {
string sOut = "Error finding frame " + sName ;
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
return false ;
}
}
return true ;
}
+76 -8
View File
@@ -14,7 +14,28 @@
#pragma once
#include "/EgtDev/Include/EGkGeomDB.h"
#include <string>
#include "/EgtDev/Include/EGnLuaMgr.h"
#include <unordered_map>
class MachMgr ;
//----------------------------------------------------------------------------
union STROKE {
struct {
double Min ;
double Max ;
} ;
double v[2] ;
} ;
//----------------------------------------------------------------------------
struct MuExit {
Point3d ptPos ;
Vector3d vtTDir ;
MuExit( const Point3d& ptP, const Vector3d& vtTD)
: ptPos( ptP), vtTDir( vtTD) {}
} ;
typedef std::vector<MuExit> MUEXITVECTOR ;
//----------------------------------------------------------------------------
class Machine
@@ -22,21 +43,68 @@ class Machine
public :
Machine( void) ;
~Machine( void) ;
bool Init( int nContextId, IGeomDB* pGeomDB, int nMachAuxId,
const std::string& sMachineDir, const std::string& sMachineName) ;
bool Init( const std::string& sMachineName, MachMgr* pMchMgr) ;
int GetMGeoId( void)
{ return m_nGroupId ; }
const std::string& GetMachineName( void)
{ return m_sName ; }
bool LoadTool( const std::string& sHead, int nExit, const std::string& sTool) ;
bool ResetHeadSet( const std::string& sHead) ;
bool SetAxisPos( const std::string& sAxis, double dVal) ;
bool GetAxisPos( const std::string& sAxis, double& dVal) ;
bool GetAxisHomePos( const std::string& sAxis, double& dHomeVal) ;
bool ResetAxisPos( const std::string& sAxis) ;
private :
void Clear( void) ;
bool LoadMachineGeometry( const std::string& sMGeoName, const Vector3d& vtOffset) ;
bool LoadMachineBase( const std::string& sName, const std::string& sGeo) ;
bool LoadMachineTable( const std::string& sName, const std::string& sParent, int nType, const std::string& sGeo) ;
bool LoadMachineAxis( const std::string& sName, const std::string& sParent, int nType,
const Point3d& ptPos, const Vector3d& vtDir,
const STROKE& Stroke, const std::string& sGeo, double dVal) ;
bool AddAxisVector( int nLay, const Point3d& ptPos, const Vector3d& vtDir, const std::string& sName) ;
bool LoadMachineStdHead( const std::string& sName, const std::string& sParent, const std::string& sHSet,
const Point3d& ptPos, const Vector3d& vtTDir,
const Vector3d& vtADir, const std::string& sGeo) ;
bool LoadMachineMultiHead( const std::string& sName, const std::string& sParent, const std::string& sHSet,
MUEXITVECTOR vMuExit,
const Vector3d& vtADir, const std::string& sGeo) ;
int GetGroup( const std::string& sGroup) ;
bool IsAxisGroup( int nGroup) ;
bool IsTableGroup( int nGroup) ;
bool IsHeadGroup( int nGroup) ;
bool AddHeadToSet( const std::string& sHSet, const std::string& sName) ;
bool GetHSet( const std::string& sHead, STRVECTOR& vsHSet) ;
bool EnableHeadInSet( const std::string& sHead) ;
bool CreateExitGroups( int nLay, int nExitNbr) ;
bool LuaInit( const std::string& sMachineName) ;
bool LuaExit( void) ;
bool LuaExecFile( const std::string& sFile) ;
private :
int m_nContextId ; // 1-based
IGeomDB* m_pGeomDB ;
std::string m_sMachineDir ;
std::string m_sName ;
int m_nGroupId ;
typedef std::unordered_map< std::string, int> STRINT_UMAP ;
private :
MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni
LuaMgr m_LuaMgr ; // interprete lua della macchina
std::string m_sName ; // nome della macchina
std::string m_sMachineDir ; // direttorio della macchina
int m_nGroupId ; // Id del gruppo della macchina
int m_nTempGroupId ; // Id del gruppo temporaneo macchina per carico
STRINT_UMAP m_mapGroups ; // dizionario dei gruppi della macchina
// Static per interprete Lua di macchina
private :
static Machine* m_pMchLua ;
private :
static int LuaEmtGeneral( lua_State* L) ;
static int LuaEmtBase( lua_State* L) ;
static int LuaEmtTable( lua_State* L) ;
static int LuaEmtAxis( lua_State* L) ;
static int LuaEmtHead( lua_State* L) ;
static int LuaEmtStdHead( lua_State* L) ;
static int LuaEmtMultiHead( lua_State* L) ;
} ;
+104
View File
@@ -0,0 +1,104 @@
//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : MachineAXes.cpp Data : 11.05.15 Versione : 1.6e3
// Contenuto : Implementazione gestione macchina : funzioni per assi.
//
//
//
// Modifiche : 11.05.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "MachMgr.h"
#include "DllMain.h"
#include "/EgtDev/Include/EGkGeoVector3d.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EGnFileUtils.h"
using namespace std ;
//----------------------------------------------------------------------------
bool
Machine::SetAxisPos( const string& sAxis, double dVal)
{
// recupero il gruppo dell'asse
int nAxGrp = GetGroup( sAxis) ;
if ( nAxGrp == GDB_ID_NULL || ! IsAxisGroup( nAxGrp))
return false ;
// recupero il tipo di asse
string sType ;
if ( ! m_pMchMgr->m_pGeomDB->GetInfo( nAxGrp, "Type", sType))
return false ;
bool bLinear = ( sType != MCH_AXIS + ToString( MCH_AT_ROTARY)) ;
// recupero la posizione attuale
double dCurrVal ;
if ( ! m_pMchMgr->m_pGeomDB->GetInfo( nAxGrp, "Val", dCurrVal))
return false ;
// recupero i limiti della corsa
STROKE Stroke ; string sTmp ;
if ( ! m_pMchMgr->m_pGeomDB->GetInfo( nAxGrp, "Stroke", sTmp) || ! FromString( sTmp, Stroke.v))
return false ;
// recupero il vettore dell'asse
int nV = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nAxGrp, sAxis) ;
const IGeoVector3d* pGV = GetGeoVector3d( m_pMchMgr->m_pGeomDB->GetGeoObj( nV)) ;
if ( pGV == nullptr)
return false ;
Point3d ptPos = pGV->GetBase() ;
Vector3d vtDir = pGV->GetVector() / AXIS_LEN ;
// limito il movimento alla corsa dell'asse
if ( dVal > Stroke.Max)
dVal = Stroke.Max ;
else if ( dVal < Stroke.Min)
dVal = Stroke.Min ;
// eseguo il movimento
if ( bLinear)
m_pMchMgr->m_pGeomDB->TranslateGroup( nAxGrp, vtDir * ( dVal - dCurrVal)) ;
else
m_pMchMgr->m_pGeomDB->RotateGroup( nAxGrp, ptPos, vtDir, ( dVal - dCurrVal)) ;
// salvo la nuova posizione
return m_pMchMgr->m_pGeomDB->SetInfo( nAxGrp, "Val", dVal) ;
}
//----------------------------------------------------------------------------
bool
Machine::GetAxisPos( const string& sAxis, double& dVal)
{
// recupero il gruppo dell'asse
int nAxGrp = GetGroup( sAxis) ;
if ( nAxGrp == GDB_ID_NULL || ! IsAxisGroup( nAxGrp))
return false ;
// recupero la posizione corrente
return m_pMchMgr->m_pGeomDB->GetInfo( nAxGrp, "Val", dVal) ;
}
//----------------------------------------------------------------------------
bool
Machine::GetAxisHomePos( const string& sAxis, double& dHomeVal)
{
// recupero il gruppo dell'asse
int nAxGrp = GetGroup( sAxis) ;
if ( nAxGrp == GDB_ID_NULL || ! IsAxisGroup( nAxGrp))
return false ;
// recupero la posizione corrente
return m_pMchMgr->m_pGeomDB->GetInfo( nAxGrp, "HVal", dHomeVal) ;
}
//----------------------------------------------------------------------------
bool
Machine::ResetAxisPos( const string& sAxis)
{
// recupero il gruppo dell'asse
int nAxGrp = GetGroup( sAxis) ;
if ( nAxGrp == GDB_ID_NULL || ! IsAxisGroup( nAxGrp))
return false ;
// recupero la posizione home
double dHomeVal ;
if ( ! m_pMchMgr->m_pGeomDB->GetInfo( nAxGrp, "HVal", dHomeVal))
return false ;
// eseguo il movimento
return SetAxisPos( sAxis, dHomeVal) ;
}
+87
View File
@@ -0,0 +1,87 @@
//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : MachineHeads.cpp Data : 10.05.15 Versione : 1.6e3
// Contenuto : Implementazione gestione macchina : funzioni per teste.
//
//
//
// Modifiche : 10.05.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "MachMgr.h"
#include "DllMain.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EGnFileUtils.h"
using namespace std ;
//----------------------------------------------------------------------------
bool
Machine::LoadTool( const string& sHead, int nExit, const string& sTool)
{
// recupero il gruppo della testa
int nHdGrp = GetGroup( sHead) ;
if ( nHdGrp == GDB_ID_NULL || ! IsHeadGroup( nHdGrp))
return false ;
// cerco il gruppo dell'uscita in quello della testa
string sExit = "T" + ToString( nExit) ;
int nExGrp = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nHdGrp, sExit) ;
if ( nExGrp == GDB_ID_NULL || m_pMchMgr->m_pGeomDB->GetGdbType( nExGrp) != GDB_TY_GROUP)
return false ;
// se utensile già montato, abilito ed esco
string sOldTool ;
if ( m_pMchMgr->m_pGeomDB->GetInfo( nExGrp, "Tool", sOldTool) && sTool == sOldTool)
return EnableHeadInSet( sHead) ;
// verifico esistenza file utensile
string sToolFile = m_sMachineDir + "\\" + TOOLS_DIR + "\\" + sTool + ".Nge" ;
if ( ! ExistsFile( sToolFile))
return false ;
// pulisco il gruppo dell'uscita
m_pMchMgr->m_pGeomDB->EmptyGroup( nExGrp) ;
// inserisco l'utensile nel gruppo
if ( ! m_pMchMgr->m_pGeomDB->Load( sToolFile, nExGrp))
return false ;
// lo ruoto 90 deg attorno alla X locale
int nT = m_pMchMgr->m_pGeomDB->GetFirstGroupInGroup( nExGrp) ;
if ( nT == GDB_ID_NULL)
return false ;
m_pMchMgr->m_pGeomDB->Rotate( nT, ORIG, X_AX, 90) ;
m_pMchMgr->m_pGeomDB->SetInfo( nExGrp, "Tool", sTool) ;
return EnableHeadInSet( sHead) ;
}
//----------------------------------------------------------------------------
bool
Machine::ResetHeadSet( const string& sHead)
{
// recupero il set della testa
STRVECTOR vsHSet ;
if ( ! GetHSet( sHead, vsHSet))
return false ;
// ciclo su tutte le teste dell'insieme per svuotarle
for ( size_t i = 0 ; i < vsHSet.size() ; ++ i) {
// recupero il gruppo della testa
int nHdGrp = GetGroup( vsHSet[i]) ;
if ( nHdGrp == GDB_ID_NULL || ! IsHeadGroup( nHdGrp))
return false ;
// ciclo sulle sue uscite
for ( int j = 1 ; true ; ++ j) {
// recupero il gruppo dell'uscita
string sExit = "T" + ToString( j) ;
int nExGrp = m_pMchMgr->m_pGeomDB->GetFirstNameInGroup( nHdGrp, sExit) ;
if ( nExGrp == GDB_ID_NULL || m_pMchMgr->m_pGeomDB->GetGdbType( nExGrp) != GDB_TY_GROUP)
break ;
// pulisco il gruppo dell'uscita
m_pMchMgr->m_pGeomDB->EmptyGroup( nExGrp) ;
m_pMchMgr->m_pGeomDB->RemoveInfo( nExGrp, "Tool") ;
}
// visualizzo solo la prima testa
m_pMchMgr->m_pGeomDB->SetStatus( nHdGrp, ( i == 0 ? GDB_ST_ON : GDB_ST_OFF)) ;
}
return true ;
}
+337
View File
@@ -0,0 +1,337 @@
//----------------------------------------------------------------------------
// 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 ;
}
+1
View File
@@ -33,3 +33,4 @@
#pragma comment(lib, EGTLIBDIR "EgtGeomKernel" EGTLIBVER ".lib")
#pragma comment(lib, EGTLIBDIR "EgtExecutor" EGTLIBVER ".lib")
#pragma comment(lib, EGTLIBDIR "SEgtLock" EGTLIBVER ".lib")
#pragma comment(lib, EGTEXTDIR "Lua/Lib/Lua52" EGTLIBVER ".lib")