diff --git a/Disposition.cpp b/Disposition.cpp index fb8a33f..4d953db 100644 --- a/Disposition.cpp +++ b/Disposition.cpp @@ -367,7 +367,7 @@ Disposition::AddFixture( const string& sName, const Point3d& ptPos, double dAngD m_pGeomDB->RotateGroup( nFixtId, ORIG, Z_AX, dAngDeg) ; // se da aggiungere alla lista if ( bAddToList) - m_vFixData.emplace_back( sName, nFixtId, ptPos, 0) ; + m_vFixData.emplace_back( sName, nFixtId, ptPos, dAngDeg) ; return nFixtId ; } diff --git a/Drilling.cpp b/Drilling.cpp index d30ab8e..4544cfd 100644 --- a/Drilling.cpp +++ b/Drilling.cpp @@ -346,21 +346,86 @@ Drilling::Apply( void) //---------------------------------------------------------------------------- bool -Drilling::GetParam( int nType, string& sVal) +Drilling::GetParam( int nType, bool& bVal) const { switch ( nType) { + case MPA_INVERT : + bVal = m_Params.m_bInvert ; + return true ; + } + return false ; +} + +//---------------------------------------------------------------------------- +bool +Drilling::GetParam( int nType, int& nVal) const +{ + return false ; +} + +//---------------------------------------------------------------------------- +bool +Drilling::GetParam( int nType, double& dVal) const +{ + switch ( nType) { + case MPA_TOOLSPEED : + dVal = m_TParams.m_dSpeed ; + return true ; + case MPA_TOOLFEED : + dVal = m_TParams.m_dFeed ; + return true ; + case MPA_TOOLSTARTFEED : + dVal = m_TParams.m_dStartFeed ; + return true ; + case MPA_TOOLENDFEED : + dVal = m_TParams.m_dEndFeed ; + return true ; + case MPA_STARTPOS : + dVal = m_Params.m_dStartPos ; + return true ; + case MPA_STARTSLOWLEN : + dVal = m_Params.m_dStartSlowLen ; + return true ; + case MPA_ENDSLOWLEN : + dVal = m_Params.m_dEndSlowLen ; + return true ; + case MPA_THROUADDLEN : + dVal = m_Params.m_dThroughAddLen ; + return true ; + case MPA_STEP : + dVal = m_Params.m_dStep ; + return true ; + case MPA_RETURNPOS : + dVal = m_Params.m_dReturnPos ; + return true ; + } + return false ; +} + +//---------------------------------------------------------------------------- +bool +Drilling::GetParam( int nType, string& sVal) const +{ + switch ( nType) { + case MPA_NAME : + sVal = m_Params.m_sName ; + return true ; case MPA_TOOL : sVal = m_Params.m_sToolName ; - break ; - default : - return false ; + return true ; + case MPA_TUUID : + sVal = ToString( m_Params.m_ToolUuid) ; + return true ; + case MPA_UUID : + sVal = ToString( m_Params.m_Uuid) ; + return true ; } - return true ; + return false ; } //---------------------------------------------------------------------------- const ToolData& -Drilling::GetToolData( void) +Drilling::GetToolData( void) const { return m_TParams ; } diff --git a/Drilling.h b/Drilling.h index 89a0fd5..f3106df 100644 --- a/Drilling.h +++ b/Drilling.h @@ -38,8 +38,11 @@ class Drilling : public Machining virtual bool SetParam( int nType, const std::string& sVal) ; virtual bool SetGeometry( const SELVECTOR& vIds) ; virtual bool Apply( void) ; - virtual bool GetParam( int nType, std::string& sVal) ; - virtual const ToolData& GetToolData( void) ; + virtual bool GetParam( int nType, bool& bVal) const ; + virtual bool GetParam( int nType, int& nVal) const ; + virtual bool GetParam( int nType, double& dVal) const ; + virtual bool GetParam( int nType, std::string& sVal) const ; + virtual const ToolData& GetToolData( void) const ; virtual bool AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP) ; public : diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 2544f2c..2de7558 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/Generator.cpp b/Generator.cpp index baddba0..8629b8c 100644 --- a/Generator.cpp +++ b/Generator.cpp @@ -22,9 +22,81 @@ #include "/EgtDev/Include/EMkToolConst.h" #include "/EgtDev/Include/EMkOperationConst.h" #include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EGnFileUtils.h" using namespace std ; +//---------------------------------------------------------------------------- +static const string ERR_EXT = ".err" ; +static const int MAX_AXES = 5 ; +static const string GLOB_VAR = "EMT" ; // tavola variabili globali +static const string GVAR_USETO1 = ".USETO1" ; // (bool) flag per utilizzo origine tavola +static const string GVAR_MODAL = ".MODAL" ; // (bool) flag per emissione modale dei valori +static const string GVAR_NUM = ".NUM" ; // (bool) flag numerazione +static const string GVAR_NUMTOK = ".Nt" ; // (string) token per numerazione +static const string GVAR_LINENBR = ".LINENBR" ; // (int) numero progressivo di linea +static const string GVAR_LINEINC = ".LINEINC" ; // (int) incremento per numero di linea +static const string GVAR_F = ".F" ; // (num) valore della feed +static const string GVAR_FTOK = ".Ft" ; // (string) token per feed +static const string GVAR_S = ".S" ; // (num) valore della speed +static const string GVAR_STOK = ".St" ; // (string) token per speed +static const string GVAR_FILE = ".FILE" ; // (string) path file di output +static const string GVAR_INFO = ".INFO" ; // (string) informazioni iniziali +static const string GVAR_DISPID = ".DISPID" ; // (int) identificativo disposizione +static const string GVAR_DISPIND = ".DISPIND" ; // (int) indice disposizione +static const string GVAR_TABNAME = ".TABNAME" ; // (string) nome tavola +static const string GVAR_TABORI1 = ".TABORI1" ; // (Point3d) prima origine di tavola +static const string GVAR_FIXID = ".FIXID" ; // (int) identificativo bloccaggio (fixture) +static const string GVAR_FIXIND = ".FIXIND" ; // (int) indice bloccaggio +static const string GVAR_FIXNAME = ".FIXNAME" ; // (string) nome bloccaggio +static const string GVAR_FIXPOS = ".FIXPOS" ; // (Point3d) posizione bloccaggio +static const string GVAR_FIXANG = ".FIXANG" ; // (num) angolo di rotazione bloccaggio +static const string GVAR_RAWID = ".RAWID" ; // (int) identificativo grezzo +static const string GVAR_RAWIND = ".RAWIND" ; // (int) indice movimento del grezzo +static const string GVAR_RAWTYPE = ".RAWTYPE" ; // (int) tipo di movimento del grezzo +static const string GVAR_RAWPOS = ".RAWPOS" ; // (Point3d) posizione di movimento del grezzo +static const string GVAR_RAWFLAG = ".RAWFLAG" ; // (int) flag per movimento del grezzo +static const string GVAR_MCHID = ".MCHID" ; // (int) identificativo lavorazione +static const string GVAR_MCHIND = ".MCHIND" ; // (int) indice lavorazione +static const string GVAR_PATHID = ".PATHID" ; // (int) identificativo percorso di lavorazione +static const string GVAR_PATHIND = ".PATHIND" ; // (int) indice percorso di lavorazione +static const string GVAR_L1 = ".L1" ; // (num) valore del primo asse lineare +static const string GVAR_L2 = ".L2" ; // (num) valore del secondo asse lineare +static const string GVAR_L3 = ".L3" ; // (num) valore del terzo asse lineare +static const string GVAR_R1 = ".R1" ; // (num) valore del primo asse rotante +static const string GVAR_R2 = ".R2" ; // (num) valore del secondo asse rotante +static const string GVAR_L1P = ".L1p" ; // (num) valore precedente del primo asse lineare +static const string GVAR_L2P = ".L2p" ; // (num) valore precedente del secondo asse lineare +static const string GVAR_L3P = ".L3p" ; // (num) valore precedente del terzo asse lineare +static const string GVAR_R1P = ".R1p" ; // (num) valore precedente del primo asse rotante +static const string GVAR_R2P = ".R2p" ; // (num) valore precedente del secondo asse rotante +static const string GVAR_L1T = ".L1t" ; // (num) token del primo asse lineare +static const string GVAR_L2T = ".L2t" ; // (num) token del secondo asse lineare +static const string GVAR_L3T = ".L3t" ; // (num) token del terzo asse lineare +static const string GVAR_R1T = ".R1t" ; // (num) token del primo asse rotante +static const string GVAR_R2T = ".R2t" ; // (num) token del secondo asse rotante +static const string GVAR_FLAG = ".FLAG" ; // (int) flag associato ad ogni movimento +static const string TEMP_VAR = "LOC" ; // tavola variabili locali (temporanee) +static const string ON_START = "OnStart" ; +static const string ON_END = "OnEnd" ; +static const string ON_PROGRAM_START = "OnProgramStart" ; +static const string ON_PROGRAM_END = "OnProgramEnd" ; +static const string ON_TOOL_SELECT = "OnToolSelect" ; +static const string ON_TOOL_DESELECT = "OnToolDeselect" ; +static const string ON_DISPOSITION_START = "OnDispositionStart" ; +static const string ON_DISPOSITION_END = "OnDispositionEnd" ; +static const string ON_TABLE_DATA = "OnTableData" ; +static const string ON_FIXTURE_DATA = "OnFixtureData" ; +static const string ON_RAWMOVE_DATA = "OnRawMoveData" ; +static const string ON_MACHINING_START = "OnMachiningStart" ; +static const string ON_MACHINING_END = "OnMachiningEnd" ; +static const string ON_PATH_START = "OnPathStart" ; +static const string ON_PATH_END = "OnPathEnd" ; +static const string ON_RAPID = "OnRapid" ; +static const string ON_LINEAR = "OnLinear" ; +static const string ON_ARC = "OnArc" ; + + //---------------------------------------------------------------------------- Generator::Generator( void) { @@ -60,24 +132,36 @@ Generator::Init( MachMgr* pMchMgr) //---------------------------------------------------------------------------- bool -Generator::Run( const string& sCncFile) +Generator::Run( const string& sCncFile, const std::string& sInfo) { + // emetto info di log + { string sOut = "Generator Run : " + sCncFile ; + LOG_INFO( GetEMkLogger(), sOut.c_str()) ; } + + // cancello l'eventuale file di uscita (e anche il file errore) + EraseFile( sCncFile) ; + string sErrFile = ChangeFileExtension( sCncFile, ERR_EXT) ; + EraseFile( sErrFile) ; + // verifico ci sia una macchinata corrente if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr || m_pMachine == nullptr || m_pMchMgr->GetCurrMachGroup() == GDB_ID_NULL) return false ; - // predispongo per la scrittura del file - if ( ! m_pMachine->WriterOpen( sCncFile)) { - LOG_INFO( GetEMkLogger(), "Error opening Cnc file") ; - return false ; + // evento inizio esecuzione + bool bOk = true ; + if ( bOk && ! OnStart()) { + bOk = false ; + LOG_INFO( GetEMkLogger(), "OnStart error") ; } - // emetto inizio programma - m_pMachine->WriterEmit( "(Start Program)") ; + // apertura file di output ed evento inizio programma + if ( bOk && ! OnProgramStart( sCncFile, sInfo)) { + bOk = false ; + LOG_INFO( GetEMkLogger(), "OnProgramStart error") ; + } // ciclo su tutte le operazioni della macchinata - bool bOk = true ; int nInd = 0 ; int nOpId = m_pMchMgr->GetFirstOperation() ; while ( bOk && nOpId != GDB_ID_NULL) { @@ -109,11 +193,23 @@ Generator::Run( const string& sCncFile) nOpId = m_pMchMgr->GetNextOperation( nOpId) ; } - // emetto fine programma - m_pMachine->WriterEmit( "(End Program)") ; + // evento fine programma + if ( bOk && ! OnProgramEnd()) { + bOk = false ; + LOG_INFO( GetEMkLogger(), "OnProgramEnd error") ; + } + // chiudo il file di output + if ( ! m_pMachine->WriterClose()) + bOk = false ; + // in caso di errore lo rinomino + if ( ! bOk) + RenameFile( sCncFile, sErrFile) ; - // chiudo il file - m_pMachine->WriterClose() ; + // evento fine esecuzione + if ( bOk && ! OnEnd()) { + bOk = false ; + LOG_INFO( GetEMkLogger(), "OnEnd error") ; + } return bOk ; } @@ -122,47 +218,54 @@ Generator::Run( const string& sCncFile) bool Generator::ProcessDisposition( int nOpId, int nOpInd) { - // parametri della disposizione + // Parametri della disposizione Disposition* pDisp = dynamic_cast( m_pGeomDB->GetUserObj( nOpId)) ; if ( pDisp == nullptr) return false ; - // emetto i dati - string sOut ; - sOut = "(" + ToString( nOpInd) + ": Disposition)" ; - m_pMachine->WriterEmit( sOut) ; + + // Emetto inizio disposizione + if ( ! OnDispositionStart( nOpId, nOpInd)) + return false ; + + // Emetto dati tavola string sTable ; pDisp->GetTable( sTable) ; - Point3d ptRef1 ; - pDisp->GetTableRef1( ptRef1) ; - sOut = "(Table=" + sTable + " R1=" + ToString( ptRef1) + ")" ; - m_pMachine->WriterEmit( sOut) ; - // bloccaggi + Point3d ptOri1 ; + pDisp->GetTableRef1( ptOri1) ; + if ( ! OnTableData( sTable, ptOri1)) + return false ; + + // Emetto dati bloccaggi for ( int i = 0 ; ; ++ i) { string sName ; int nId ; Point3d ptPos ; double dAngDeg ; if ( pDisp->GetFixtureData( i, sName, nId, ptPos, dAngDeg)) { - sOut = "(Fixture " + sName + " " + ToString( nId) + " (" + ToString( ptPos) + ") " + ToString( dAngDeg) + ")" ; - m_pMachine->WriterEmit( sOut) ; + if ( ! OnFixtureData( nId, i + 1, sName, ptPos, dAngDeg)) + return false ; } else break ; } - // movimento grezzi + + // Emetto movimenti sui grezzi for ( int i = 0 ; ; ++ i) { int nRawId ; int nType ; Point3d ptPos ; int nFlag ; if ( pDisp->GetMoveRawData( i, nRawId, nType, ptPos, nFlag)) { - sOut = "(MoveRaw " + ToString( nRawId) + " " + ToString( nType) + " (" + ToString( ptPos) + ") " + ToString( nFlag) + ")" ; - m_pMachine->WriterEmit( sOut) ; + if ( ! OnRawMoveData( nRawId, i + 1, nType, ptPos, nFlag)) + return false ; } else break ; } - m_pMachine->WriterEmit( "(End Disposition)") ; + + // Emetto fine disposizione + if ( ! OnDispositionEnd()) + return false ; return true ; } @@ -171,31 +274,35 @@ Generator::ProcessDisposition( int nOpId, int nOpInd) bool Generator::ProcessMachining( int nOpId, int nOpInd) { - // parametri della lavorazione - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nOpId)) ; - if ( pMch == nullptr) + // Imposto come lavorazione corrente + if ( ! m_pMchMgr->SetCurrMachining( nOpId)) return false ; - // emetto inizio lavorazione - { string sOut ; - string sName ; - m_pGeomDB->GetName( nOpId, sName) ; - sOut = "(" + ToString( nOpInd) + ": Machining=" + sName + ")" ; - m_pMachine->WriterEmit( sOut) ; } - - // aggiorno utensile e assi macchina - if ( ! UpdateTool( nOpId) || ! UpdateAxes()) + // Recupero l'utensile della lavorazione corrente + string sTool ; + if ( ! m_pMchMgr->GetMachiningParam( MPA_TOOL, sTool)) return false ; - // parametri dell'utensile - const ToolData& Tdata = pMch->GetToolData() ; + // Se utensile cambierà + if ( ! m_sTool.empty() && m_sTool != sTool) { + // emetto deselezione vecchio utensile + if ( ! OnToolDeselect()) + return false ; + } + // Aggiorno utensile e assi macchina + if ( ! UpdateTool( sTool) || ! UpdateAxes()) + return false ; + // Se utensile cambiato, emetto selezione nuovo utensile + if ( m_sTool != m_sPrevTool) { + if ( ! OnToolSelect()) + return false ; + } - // Emetto dati utensile - { string sOut ; - sOut = "(Tool " + m_sTool + ( m_sTool != m_sPrevTool ? " changed" : "") + " S=" + ToString(Tdata.m_dSpeed) + ")" ; - m_pMachine->WriterEmit( sOut) ; } + // Emetto inizio lavorazione + if ( ! OnMachiningStart( nOpId, nOpInd)) + return false ; - // ciclo su tutti i percorsi CL della lavorazione + // Ciclo su tutti i percorsi CL della lavorazione bool bOk = true ; int nClPathInd = 0 ; int nClId = m_pGeomDB->GetFirstNameInGroup( nOpId, MCH_CL) ; @@ -209,8 +316,8 @@ Generator::ProcessMachining( int nOpId, int nOpInd) nClPathId = m_pGeomDB->GetNextGroup( nClPathId) ; } - // emetto fine lavorazione - m_pMachine->WriterEmit( "(End Machining)") ; + // Emetto fine lavorazione + bOk = bOk && OnMachiningEnd() ; return bOk ; } @@ -219,10 +326,11 @@ Generator::ProcessMachining( int nOpId, int nOpInd) bool Generator::ProcessClPath( int nClPathId, int nClPathInd, int nOpId, int nOpInd) { - string sOut = "(ClPath " + ToString( nClPathInd) + ")" ; - m_pMachine->WriterEmit( sOut) ; + // Emetto inizio percorso di lavoro + if ( ! OnPathStart( nClPathId, nClPathInd)) + return false ; - // ciclo su tutte le entità del percorsi CL + // Ciclo su tutte le entità del percorsi CL bool bOk = true ; int nEntInd = 0 ; int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; @@ -234,7 +342,9 @@ Generator::ProcessClPath( int nClPathId, int nClPathInd, int nOpId, int nOpInd) // passo all'entità successivo nEntId = m_pGeomDB->GetNext( nEntId) ; } - m_pMachine->WriterEmit( "(End ClPath)") ; + + // Emetto fine percorso di lavoro + bOk = bOk && OnPathEnd() ; return bOk ; } @@ -251,33 +361,30 @@ Generator::ProcessClEnt( int nEntId, int nEntInd, int nClPathId, int nClPathInd, // Verifico se movimento in rapido bool bRapid = ( pCamData->GetFeed() < EPS_SMALL) ; // Emetto movimento - string sOut ; - sOut += ( bRapid ? "G0 " : "G1 ") ; - for ( size_t i = 0 ; i < m_AxesName.size() ; ++ i) { - sOut += m_AxesName[i] + ToString( AxesEnd[i], 3) + " " ; + if ( bRapid) { + if ( ! OnRapid( AxesEnd)) + return false ; + } + else { + if ( ! OnLinear( AxesEnd, pCamData->GetFeed(), pCamData->GetFlag())) + return false ; } - if ( ! bRapid) - sOut += "F" + ToString( pCamData->GetFeed()) ; - m_pMachine->WriterEmit( sOut) ; return true ; } //---------------------------------------------------------------------------- bool -Generator::UpdateTool( int nOpId) +Generator::UpdateTool( const string& sTool) { // Salvo l'utensile attuale come precedente m_sPrevTool = m_sTool ; - // Recupero l'utensile della lavorazione corrente - string sTool ; - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nOpId)) ; - if ( pMch == nullptr || ! pMch->GetParam( MPA_TOOL, sTool)) - return false ; - if ( ! m_pMchMgr->TdbSetCurrTool( sTool)) - return false ; - // se cambiato, attivo l'utensile della lavorazione + // Se cambiato ... if ( sTool != m_sTool) { + // lo imposto come corrente + if ( ! m_pMchMgr->TdbSetCurrTool( sTool)) + return false ; + // lo carico in macchina string sHead ; m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ; int nExit ; m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ; if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) @@ -294,3 +401,338 @@ Generator::UpdateAxes( void) // Carico i nomi degli assi macchina attivi return m_pMachine->GetAllCurrAxesName( m_AxesName) ; } + +//---------------------------------------------------------------------------- +bool +Generator::OnStart( void) +{ + // definisco tavola variabili globali + bool bOk = m_pMachine->LuaCreateGlobTable( GLOB_VAR) ; + // definisco tavola variabili locali (temporanee) + bOk = bOk && m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // assegno valori di default + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_USETO1, false) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MODAL, false) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NUM, false) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NUMTOK, "N") ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_LINENBR, 0) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_LINEINC, 1) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_FTOK, "F") ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_STOK, "S") ; + // chiamo la funzione + bOk = bOk && m_pMachine->LuaCallFunction( ON_START) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnEnd( void) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // chiamo la funzione + bOk = bOk && m_pMachine->LuaCallFunction( ON_END) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnProgramStart( const string& sCncFile, const string& sInfo) +{ + // apro il file di output + bool bOk = m_pMachine->WriterOpen( sCncFile) ; + if ( ! bOk) + LOG_INFO( GetEMkLogger(), "Error opening Cnc file") ; + // assegno nome file + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_FILE, sCncFile) ; + // definisco tavola variabili locali (temporanee) + bOk = bOk && m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // assegno info + string sTxt = sInfo + " " + CurrDateTime() ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_INFO, sTxt) ; + // chiamo la funzione di inizio programma + bOk = bOk && m_pMachine->LuaCallFunction( ON_PROGRAM_START) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnProgramEnd( void) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // chiamo fine programma + bOk = bOk && m_pMachine->LuaCallFunction( ON_PROGRAM_END) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnDispositionStart( int nOpId, int nOpInd) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // assegno identificativo e indice disposizione + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_DISPID, nOpId) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_DISPIND, nOpInd) ; + // chiamo la funzione di inizio disposizione + bOk = bOk && m_pMachine->LuaCallFunction( ON_DISPOSITION_START) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnDispositionEnd( void) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // chiamo la funzione di fine disposizione + bOk = bOk && m_pMachine->LuaCallFunction( ON_DISPOSITION_END) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnTableData( const string& sName, const Point3d& ptOri1) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // assegno nome tavola e valore riferimento + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_TABNAME, sName) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_TABORI1, ptOri1) ; + // chiamo la funzione di gestione dati tavola + bOk = bOk && m_pMachine->LuaCallFunction( ON_TABLE_DATA) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnFixtureData( int nFixId, int nFixInd, const string& sName, const Point3d& ptPos, double dAngDeg) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // assegno dati bloccaggio + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_FIXID, nFixId) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_FIXIND, nFixInd) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_FIXNAME, sName) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_FIXPOS, ptPos) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_FIXANG, dAngDeg) ; + // chiamo la funzione di gestione dati bloccaggio + bOk = bOk && m_pMachine->LuaCallFunction( ON_FIXTURE_DATA) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnRawMoveData( int nRawId, int RawMoveInd, int nType, const Point3d& ptPos, int nFlag) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // assegno dati bloccaggio + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_RAWID, nRawId) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_RAWIND, RawMoveInd) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_RAWTYPE, nType) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_RAWPOS, ptPos) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_RAWFLAG, nFlag) ; + // chiamo la funzione di gestione movimento del grezzo + bOk = bOk && m_pMachine->LuaCallFunction( ON_RAWMOVE_DATA) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnToolSelect( void) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // assegno il nome degli assi + int nNumAxes = int( m_AxesName.size()) ; + for ( int i = 1 ; i <= MAX_AXES ; ++ i) { + if ( i <= nNumAxes) + bOk = bOk && m_pMachine->LuaSetGlobVar( GetGlobVarAxisToken(i), m_AxesName[i-1]) ; + else + bOk = bOk && m_pMachine->LuaResetGlobVar( GetGlobVarAxisToken(i)) ; + } + // chiamo la funzione di selezione utensile + bOk = bOk && m_pMachine->LuaCallFunction( ON_TOOL_SELECT) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnToolDeselect( void) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // chiamo la funzione di deselezione utensile + bOk = bOk && m_pMachine->LuaCallFunction( ON_TOOL_DESELECT) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnMachiningStart( int nOpId, int nOpInd) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // assegno identificativo e indice lavorazione + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MCHID, nOpId) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MCHIND, nOpInd) ; + // chiamo la funzione di inizio lavorazione + bOk = bOk && m_pMachine->LuaCallFunction( ON_MACHINING_START) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnMachiningEnd( void) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // chiamo la funzione di fine lavorazione + bOk = bOk && m_pMachine->LuaCallFunction( ON_MACHINING_END) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnPathStart( int nClPathId, int nClPathInd) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // assegno identificativo e indice percorso di lavorazione + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_PATHID, nClPathId) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_PATHIND, nClPathInd) ; + // chiamo la funzione di inizio percorso di lavorazione + bOk = bOk && m_pMachine->LuaCallFunction( ON_PATH_START) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnPathEnd( void) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // chiamo la funzione di fine percorso di lavorazione + bOk = bOk && m_pMachine->LuaCallFunction( ON_PATH_END) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnRapid( const DBLVECTOR& AxesEnd) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // assegno il valore degli assi + int nNumAxes = int( AxesEnd.size()) ; + for ( int i = 1 ; i <= MAX_AXES ; ++ i) { + if ( i <= nNumAxes) + bOk = bOk && m_pMachine->LuaSetGlobVar( GetGlobVarAxisValue(i), AxesEnd[i-1]) ; + else + bOk = bOk && m_pMachine->LuaResetGlobVar( GetGlobVarAxisValue(i)) ; + } + // chiamo la funzione di movimento in rapido + bOk = bOk && m_pMachine->LuaCallFunction( ON_RAPID) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Generator::OnLinear( const DBLVECTOR& AxesEnd, double dFeed, int nFlag) +{ + // definisco tavola variabili locali (temporanee) + bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; + // assegno il valore degli assi + int nNumAxes = int( AxesEnd.size()) ; + for ( int i = 1 ; i <= MAX_AXES ; ++ i) { + if ( i <= nNumAxes) + bOk = bOk && m_pMachine->LuaSetGlobVar( GetGlobVarAxisValue(i), AxesEnd[i-1]) ; + else + bOk = bOk && m_pMachine->LuaResetGlobVar( GetGlobVarAxisValue(i)) ; + } + // assegno il valore della feed + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_F, dFeed) ; + // assegno il valore del flag + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_FLAG, nFlag) ; + // chiamo la funzione di movimento in rapido + bOk = bOk && m_pMachine->LuaCallFunction( ON_LINEAR) ; + // cancello variabili locali + bOk = bOk && m_pMachine->LuaResetGlobVar( TEMP_VAR) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +string +Generator::GetGlobVarAxisValue( int nAx) +{ + switch ( nAx) { + case 1 : return ( GLOB_VAR + GVAR_L1) ; + case 2 : return ( GLOB_VAR + GVAR_L2) ; + case 3 : return ( GLOB_VAR + GVAR_L3) ; + case 4 : return ( GLOB_VAR + GVAR_R1) ; + case 5 : return ( GLOB_VAR + GVAR_R2) ; + default : return "" ; + } +} + +//---------------------------------------------------------------------------- +string +Generator::GetGlobVarAxisPrev( int nAx) +{ + switch ( nAx) { + case 1 : return ( GLOB_VAR + GVAR_L1P) ; + case 2 : return ( GLOB_VAR + GVAR_L2P) ; + case 3 : return ( GLOB_VAR + GVAR_L3P) ; + case 4 : return ( GLOB_VAR + GVAR_R1P) ; + case 5 : return ( GLOB_VAR + GVAR_R2P) ; + default : return "" ; + } +} + +//---------------------------------------------------------------------------- +string +Generator::GetGlobVarAxisToken( int nAx) +{ + switch ( nAx) { + case 1 : return ( GLOB_VAR + GVAR_L1T) ; + case 2 : return ( GLOB_VAR + GVAR_L2T) ; + case 3 : return ( GLOB_VAR + GVAR_L3T) ; + case 4 : return ( GLOB_VAR + GVAR_R1T) ; + case 5 : return ( GLOB_VAR + GVAR_R2T) ; + default : return "" ; + } +} diff --git a/Generator.h b/Generator.h index 0048785..083c35e 100644 --- a/Generator.h +++ b/Generator.h @@ -26,15 +26,36 @@ class Generator Generator( void) ; ~Generator( void) ; bool Init( MachMgr* pMchMgr) ; - bool Run( const std::string& sCncFile) ; + bool Run( const std::string& sCncFile, const std::string& sInfo) ; private : bool ProcessDisposition( int nOpId, int nOpInd) ; bool ProcessMachining( int nOpId, int nOpInd) ; bool ProcessClPath( int nClPathId, int nClPathInd, int nOpId, int nOpInd) ; bool ProcessClEnt( int nEntId, int nEntInd, int nClPathId, int nClPathInd, int nOpId, int nOpInd) ; - bool UpdateTool( int nOpId) ; + bool UpdateTool( const std::string& sTool) ; bool UpdateAxes( void) ; + bool OnStart( void) ; + bool OnEnd( void) ; + bool OnProgramStart( const std::string& sCncFile, const std::string& sInfo) ; + bool OnProgramEnd( void) ; + bool OnToolSelect( void) ; + bool OnToolDeselect( void) ; + bool OnDispositionStart( int nOpId, int nOpInd) ; + bool OnDispositionEnd( void) ; + bool OnTableData( const std::string& sName, const Point3d& ptOri1) ; + bool OnFixtureData( int nFixId, int nFixInd, const std::string& sName, + const Point3d& ptPos, double dAngDeg) ; + bool OnRawMoveData( int nRawId, int RawMoveInd, int nType, const Point3d& ptPos, int nFlag) ; + bool OnMachiningStart( int nOpId, int nOpInd) ; + bool OnMachiningEnd( void) ; + bool OnPathStart( int nClPathId, int nClPathInd) ; + bool OnPathEnd( void) ; + bool OnRapid( const DBLVECTOR& AxesEnd) ; + bool OnLinear( const DBLVECTOR& AxesEnd, double dFeed, int nFlag) ; + std::string GetGlobVarAxisValue( int nAx) ; + std::string GetGlobVarAxisPrev( int nAx) ; + std::string GetGlobVarAxisToken( int nAx) ; private : MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni diff --git a/MachMgr.h b/MachMgr.h index 1c62147..f18e9ac 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -163,6 +163,10 @@ class MachMgr : public IMachMgr virtual bool SetMachiningParam( int nType, const std::string& sVal) ; virtual bool SetMachiningGeometry( const SELVECTOR& vIds) ; virtual bool MachiningApply( void) ; + virtual bool GetMachiningParam( int nType, bool& bVal) const ; + virtual bool GetMachiningParam( int nType, int& dVal) const ; + virtual bool GetMachiningParam( int nType, double& dVal) const ; + virtual bool GetMachiningParam( int nType, std::string& sVal) const ; // Simulation virtual bool SimStart( void) ; virtual bool SimMove( void) ; @@ -170,7 +174,7 @@ class MachMgr : public IMachMgr virtual bool SimSetStep( double dStep) ; virtual bool SimStop( void) ; // Generation - virtual bool Generate( const std::string& sCncFile) ; + virtual bool Generate( const std::string& sCncFile, const std::string& sInfo) ; // Machine Calc virtual bool SetCalcTable( const std::string& sTable) ; virtual bool SetCalcTool( const std::string& sTool, const std::string& sHead, int nExit) ; @@ -231,6 +235,7 @@ class MachMgr : public IMachMgr double GetCalcRot1W( void) ; // operations bool GetOperationNewName( std::string& sName) const ; + const ToolData* GetMachiningToolData( void) const ; private : // Basic diff --git a/MachMgrGeneration.cpp b/MachMgrGeneration.cpp index 9daed89..b9ab9d1 100644 --- a/MachMgrGeneration.cpp +++ b/MachMgrGeneration.cpp @@ -22,7 +22,7 @@ using namespace std ; //---------------------------------------------------------------------------- bool -MachMgr::Generate( const string& sCncFile) +MachMgr::Generate( const string& sCncFile, const std::string& sInfo) { // inizializzazione generatore Generator genPP ; @@ -31,7 +31,7 @@ MachMgr::Generate( const string& sCncFile) return false ; } // esecuzione della generazione - if ( ! genPP.Run( sCncFile)) { + if ( ! genPP.Run( sCncFile, sInfo)) { LOG_ERROR( GetEMkLogger(), "Error on Generate Run") return false ; } diff --git a/MachMgrOperations.cpp b/MachMgrOperations.cpp index c59552b..e51416c 100644 --- a/MachMgrOperations.cpp +++ b/MachMgrOperations.cpp @@ -441,4 +441,84 @@ MachMgr::MachiningApply( void) return false ; // imposto la geometria return pMch->Apply() ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::GetMachiningParam( int nType, bool& bVal) const +{ + // recupero la lavorazione corrente + int nCurrMchId = GetCurrMachining() ; + if ( nCurrMchId == GDB_ID_NULL) + return false ; + // ne recupero il gestore + Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + if ( pMch == nullptr) + return false ; + // recupero il parametro + return pMch->GetParam( nType, bVal) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::GetMachiningParam( int nType, int& nVal) const +{ + // recupero la lavorazione corrente + int nCurrMchId = GetCurrMachining() ; + if ( nCurrMchId == GDB_ID_NULL) + return false ; + // ne recupero il gestore + Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + if ( pMch == nullptr) + return false ; + // recupero il parametro + return pMch->GetParam( nType, nVal) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::GetMachiningParam( int nType, double& dVal) const +{ + // recupero la lavorazione corrente + int nCurrMchId = GetCurrMachining() ; + if ( nCurrMchId == GDB_ID_NULL) + return false ; + // ne recupero il gestore + Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + if ( pMch == nullptr) + return false ; + // recupero il parametro + return pMch->GetParam( nType, dVal) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::GetMachiningParam( int nType, string& sVal) const +{ + // recupero la lavorazione corrente + int nCurrMchId = GetCurrMachining() ; + if ( nCurrMchId == GDB_ID_NULL) + return false ; + // ne recupero il gestore + Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + if ( pMch == nullptr) + return false ; + // recupero il parametro + return pMch->GetParam( nType, sVal) ; +} + +//---------------------------------------------------------------------------- +const ToolData* +MachMgr::GetMachiningToolData( void) const +{ + // recupero la lavorazione corrente + int nCurrMchId = GetCurrMachining() ; + if ( nCurrMchId == GDB_ID_NULL) + return nullptr ; + // ne recupero il gestore + Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + if ( pMch == nullptr) + return nullptr ; + // recupero il parametro + return &( pMch->GetToolData()) ; } \ No newline at end of file diff --git a/Machine.h b/Machine.h index e6d4d04..91041e6 100644 --- a/Machine.h +++ b/Machine.h @@ -14,7 +14,9 @@ #pragma once #include "MachineStruConst.h" +#include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EGkGeomDB.h" +#include "/EgtDev/Include/EGkLuaAux.h" #include "/EgtDev/Include/EGnLuaMgr.h" #include "/EgtDev/Include/EGnWriter.h" #include @@ -63,6 +65,13 @@ class Machine bool GetPositions( const Point3d& ptP, double dA, double dB, int& nStat, double& dX, double& dY, double& dZ) ; bool VerifyOutOfStroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) ; + bool LuaCallFunction( const std::string& sFun) ; + bool LuaCreateGlobTable( const std::string& sName) ; + bool LuaResetGlobVar( const std::string& sName) ; + template + bool LuaSetGlobVar( const std::string& sVar, const T& Val) ; + template + bool LuaGetGlobVar( const std::string& sVar, T& Val) ; bool WriterOpen( const std::string& sOutFile) ; bool WriterClose( void) ; bool WriterEmit( const std::string& sLine) ; @@ -101,7 +110,6 @@ class Machine bool CalculateKinematicChain( void) ; bool AddKinematicAxis( bool bOnHead, int nId) ; bool AdjustAngleInStroke( int nId, double& dAng) ; - bool LuaInit( const std::string& sMachineName) ; bool LuaExit( void) ; bool LuaLoadMachine( const std::string& sFile) ; @@ -143,4 +151,43 @@ class Machine static int LuaEmtHead( lua_State* L) ; static int LuaEmtStdHead( lua_State* L) ; static int LuaEmtMultiHead( lua_State* L) ; + static int LuaEmtWrite( lua_State* L) ; } ; + +//---------------------------------------------------------------------------- +template +bool +Machine::LuaSetGlobVar( const std::string& sVar, const T& Val) +{ + // imposto contesto corretto + int nOldCtx = ExeGetCurrentContext() ; + if ( nOldCtx != m_pMchMgr->GetContextId()) + ExeSetCurrentContext( m_pMchMgr->GetContextId()) ; + // imposto l'oggetto corrente per Lua + m_pMchLua = this ; + // eseguo l'assegnamento + bool bOk = ::LuaSetGlobVar( m_LuaMgr.GetLuaState(), sVar, Val) ; + // ripristino contesto originale + if ( nOldCtx != m_pMchMgr->GetContextId()) + ExeSetCurrentContext( nOldCtx) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +template +bool +Machine::LuaGetGlobVar( const std::string& sVar, T& Val) +{ + // imposto contesto corretto + int nOldCtx = ExeGetCurrentContext() ; + if ( nOldCtx != m_pMchMgr->GetContextId()) + ExeSetCurrentContext( m_pMchMgr->GetContextId()) ; + // imposto l'oggetto corrente per Lua + m_pMchLua = this ; + // eseguo la lettura + bool bOk = ::LuaGetGlobVar( m_LuaMgr.GetLuaState(), sVar, Val) ; + // ripristino contesto originale + if ( nOldCtx != m_pMchMgr->GetContextId()) + ExeSetCurrentContext( nOldCtx) ; + return bOk ; +} diff --git a/MachineLua.cpp b/MachineLua.cpp index 8e24283..76b7608 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -54,6 +54,8 @@ Machine::LuaInit( const string& sMachineName) m_LuaMgr.RegisterFunction( "EmtTable", Machine::LuaEmtTable) ; m_LuaMgr.RegisterFunction( "EmtAxis", Machine::LuaEmtAxis) ; m_LuaMgr.RegisterFunction( "EmtHead", Machine::LuaEmtHead) ; + // registro le funzioni di scrittura part program per lua + m_LuaMgr.RegisterFunction( "EmtWrite", Machine::LuaEmtWrite) ; return true ; } @@ -70,6 +72,60 @@ Machine::LuaExit( void) return true ; } +//---------------------------------------------------------------------------- +bool +Machine::LuaCallFunction( const string& sFun) +{ + // imposto contesto corretto + int nOldCtx = ExeGetCurrentContext() ; + if ( nOldCtx != m_pMchMgr->GetContextId()) + ExeSetCurrentContext( m_pMchMgr->GetContextId()) ; + // imposto l'oggetto corrente per Lua + m_pMchLua = this ; + // eseguo la funzione + bool bOk = m_LuaMgr.CallFunction( sFun, 0) ; + // ripristino contesto originale + if ( nOldCtx != m_pMchMgr->GetContextId()) + ExeSetCurrentContext( nOldCtx) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Machine::LuaCreateGlobTable( const string& sName) +{ + // imposto contesto corretto + int nOldCtx = ExeGetCurrentContext() ; + if ( nOldCtx != m_pMchMgr->GetContextId()) + ExeSetCurrentContext( m_pMchMgr->GetContextId()) ; + // imposto l'oggetto corrente per Lua + m_pMchLua = this ; + // eseguo la funzione + bool bOk = ::LuaCreateGlobTable( m_LuaMgr.GetLuaState(), sName) ; + // ripristino contesto originale + if ( nOldCtx != m_pMchMgr->GetContextId()) + ExeSetCurrentContext( nOldCtx) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Machine::LuaResetGlobVar( const string& sName) +{ + // imposto contesto corretto + int nOldCtx = ExeGetCurrentContext() ; + if ( nOldCtx != m_pMchMgr->GetContextId()) + ExeSetCurrentContext( m_pMchMgr->GetContextId()) ; + // imposto l'oggetto corrente per Lua + m_pMchLua = this ; + // eseguo la funzione + bool bOk = ::LuaResetGlobVar( m_LuaMgr.GetLuaState(), sName) ; + // ripristino contesto originale + if ( nOldCtx != m_pMchMgr->GetContextId()) + ExeSetCurrentContext( nOldCtx) ; + return bOk ; +} + //---------------------------------------------------------------------------- bool Machine::LuaLoadMachine( const string& sFile) @@ -104,10 +160,15 @@ Machine::LuaEmtGeneral( lua_State* L) // lettura eventuale campo 'Offset' dalla tabella (default 0,0,0) Vector3d vtOffset ; LuaGetTabFieldParam( L, 1, "Offset", vtOffset) ; + // lettura eventuale campo 'Processor' dalla tabella + string sProcessor ; + LuaGetTabFieldParam( L, 1, "Processor", sProcessor) ; LuaClearStack( L) ; // info string sOut = "LuaEmtGeneral : " + sFile ; + if ( ! sProcessor.empty()) + sOut += ", " + sProcessor ; LOG_INFO( GetEMkLogger(), sOut.c_str()) // verifico ci sia una macchina attiva @@ -118,6 +179,17 @@ Machine::LuaEmtGeneral( lua_State* L) if ( ! m_pMchLua->LoadMachineGeometry( sFile, vtOffset)) return luaL_error( L, " Load Machine failed") ; + // carico il processore della macchina + if ( ! sProcessor.empty()) { + // carico il file lua del processore + string sProcPath = m_pMchLua->m_sMachineDir + "\\" + sProcessor ; + if ( ! m_pMchLua->m_LuaMgr.ExecFile( sProcPath)) + return luaL_error( L, " Load Processor failed") ; + } + else { + LOG_INFO( GetEMkLogger(), " Processor file not specified") + } + return 0 ; } @@ -364,3 +436,18 @@ Machine::LuaEmtMultiHead( lua_State* L) return 0 ; } + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtWrite( lua_State* L) +{ + // 1 parametro : string + string sOut ; + LuaCheckParam( L, 1, sOut) + LuaClearStack( L) ; + // emetto stringa + bool bOk = m_pMchLua->WriterEmit( sOut) ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} \ No newline at end of file diff --git a/MachineWriter.cpp b/MachineWriter.cpp index 1a4f942..329afa4 100644 --- a/MachineWriter.cpp +++ b/MachineWriter.cpp @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- -// File : MachineLua.cpp Data : 29.10.15 Versione : 1.6j4 +// File : MachineWriter.cpp Data : 29.10.15 Versione : 1.6j4 // Contenuto : Implementazione gestione macchina : funzioni output. // // diff --git a/Machining.h b/Machining.h index 706b7c6..c9040b0 100644 --- a/Machining.h +++ b/Machining.h @@ -39,10 +39,12 @@ class Machining : public IUserObj virtual bool SetParam( int nType, double dVal) = 0 ; virtual bool SetParam( int nType, const std::string& sVal) = 0 ; virtual bool SetGeometry( const SELVECTOR& vIds) = 0 ; - //virtual bool ResetGeometry( void) = 0 ; virtual bool Apply( void) = 0 ; - virtual bool GetParam( int nType, std::string& sVal) = 0 ; - virtual const ToolData& GetToolData( void) = 0 ; + virtual bool GetParam( int nType, bool& bVal) const = 0 ; + virtual bool GetParam( int nType, int& nVal) const = 0 ; + virtual bool GetParam( int nType, double& dVal) const = 0 ; + virtual bool GetParam( int nType, std::string& sVal) const = 0 ; + virtual const ToolData& GetToolData( void) const = 0 ; virtual bool AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP) = 0 ; protected : diff --git a/MachiningsMgr.cpp b/MachiningsMgr.cpp index 07a127d..09f2762 100644 --- a/MachiningsMgr.cpp +++ b/MachiningsMgr.cpp @@ -17,6 +17,7 @@ #include "MachiningDataFactory.h" #include "DllMain.h" #include "/EgtDEv/Include/EmkMachiningConst.h" +#include "/EgtDEv/Include/EGnStringKeyVal.h" #include "/EgtDEv/Include/EGnStringUtils.h" #include "/EgtDEv/Include/EGnFileUtils.h" #include "/EgtDEv/Include/EGnScanner.h" @@ -112,6 +113,10 @@ MachiningsMgr::Load( const string& sMachsFile, const ToolsMgr* pTsMgr) string sOut = "LoadMachinings : Error on Header" ; LOG_ERROR( GetEMkLogger(), sOut.c_str()) } + { + string sOut = "LoadMachinings : FileVer = " + ToString( nVersion) + " CurrVer = " + ToString( MF_CURR_VER) ; + LOG_INFO( GetEMkLogger(), sOut.c_str()) + } // dimensiono map const int MIN_BUCKETS = 163 ; @@ -205,9 +210,7 @@ MachiningsMgr::LoadOneMachining( Scanner& TheScanner, bool& bEnd) } // eventuale lettura da file if ( TheScanner.GetLine( sLine)) { - string sKey, sVal ; - SplitFirst( sLine, "=", sKey, sVal) ; - if ( ! (sKey == MF_SIZE && FromString( sVal, nSize))) + if ( ! GetVal( sLine, MF_SIZE, nSize)) TheScanner.UngetLine( sLine) ; } // leggo i dati della lavorazione diff --git a/Milling.cpp b/Milling.cpp index e1d6f0e..01f5fbb 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -202,14 +202,78 @@ Milling::Apply( void) //---------------------------------------------------------------------------- bool -Milling::GetParam( int nType, string& sVal) +Milling::GetParam( int nType, bool& bVal) const { return false ; } +//---------------------------------------------------------------------------- +bool +Milling::GetParam( int nType, int& nVal) const +{ + return false ; +} + +//---------------------------------------------------------------------------- +bool +Milling::GetParam( int nType, double& dVal) const +{ + switch ( nType) { + case MPA_TOOLSPEED : + dVal = m_TParams.m_dSpeed ; + return true ; + case MPA_TOOLFEED : + dVal = m_TParams.m_dFeed ; + return true ; + case MPA_TOOLSTARTFEED : + dVal = m_TParams.m_dStartFeed ; + return true ; + case MPA_TOOLENDFEED : + dVal = m_TParams.m_dEndFeed ; + return true ; + case MPA_TOOLTIPFEED : + dVal = m_TParams.m_dTipFeed ; + return true ; + case MPA_TOOLOFFSR : + dVal = m_TParams.m_dOffsR ; + return true ; + case MPA_TOOLOFFSL : + dVal = m_TParams.m_dOffsL ; + return true ; + case MPA_SIDEANGLE : + dVal = m_Params.m_dSideAngle ; + return true ; + } + return false ; +} + +//---------------------------------------------------------------------------- +bool +Milling::GetParam( int nType, string& sVal) const +{ + switch ( nType) { + case MPA_NAME : + sVal = m_Params.m_sName ; + return true ; + case MPA_TOOL : + sVal = m_Params.m_sToolName ; + return true ; + case MPA_DEPTH_STR : + sVal = m_Params.m_sDepth ; + return true ; + case MPA_TUUID : + sVal = ToString( m_Params.m_ToolUuid) ; + return true ; + case MPA_UUID : + sVal = ToString( m_Params.m_Uuid) ; + return true ; + } + return false ; +} + //---------------------------------------------------------------------------- const ToolData& -Milling::GetToolData( void) +Milling::GetToolData( void) const { return m_TParams ; } diff --git a/Milling.h b/Milling.h index cc1e374..59e6eeb 100644 --- a/Milling.h +++ b/Milling.h @@ -38,8 +38,11 @@ class Milling : public Machining virtual bool SetParam( int nType, const std::string& sVal) ; virtual bool SetGeometry( const SELVECTOR& vIds) ; virtual bool Apply( void) ; - virtual bool GetParam( int nType, std::string& sVal) ; - virtual const ToolData& GetToolData( void) ; + virtual bool GetParam( int nType, bool& bVal) const ; + virtual bool GetParam( int nType, int& nVal) const ; + virtual bool GetParam( int nType, double& dVal) const ; + virtual bool GetParam( int nType, std::string& sVal) const ; + virtual const ToolData& GetToolData( void) const ; virtual bool AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP) ; public : diff --git a/Sawing.cpp b/Sawing.cpp index 3a333fe..5780a44 100644 --- a/Sawing.cpp +++ b/Sawing.cpp @@ -359,24 +359,110 @@ Sawing::Apply( void) //---------------------------------------------------------------------------- bool -Sawing::GetParam( int nType, string& sVal) +Sawing::GetParam( int nType, bool& bVal) const { switch ( nType) { + case MPA_INVERT : + bVal = m_Params.m_bInvert ; + return true ; + case MPA_TOANDFROM : + bVal = m_Params.m_bToAndFrom ; + return true ; + } + return false ; +} + +//---------------------------------------------------------------------------- +bool +Sawing::GetParam( int nType, int& nVal) const +{ + switch ( nType) { + case MPA_WORKSIDE : + nVal = m_Params.m_nWorkSide ; + return true ; + case MPA_HEADSIDE : + nVal = m_Params.m_nHeadSide ; + return true ; + case MPA_LEADINTYPE : + nVal = m_Params.m_nLeadInType ; + return true ; + case MPA_EXTLINKTYPE : + nVal = m_Params.m_nExtLinkType ; + return true ; + case MPA_LEADOUTTYPE : + nVal = m_Params.m_nLeadOutType ; + return true ; + case MPA_CURVEUSE : + nVal = m_Params.m_nCurveUse ; + return true ; + } + return false ; +} + +//---------------------------------------------------------------------------- +bool +Sawing::GetParam( int nType, double& dVal) const +{ + switch ( nType) { + case MPA_TOOLSPEED : + dVal = m_TParams.m_dSpeed ; + return true ; + case MPA_TOOLFEED : + dVal = m_TParams.m_dFeed ; + return true ; + case MPA_TOOLSTARTFEED : + dVal = m_TParams.m_dStartFeed ; + return true ; + case MPA_TOOLENDFEED : + dVal = m_TParams.m_dEndFeed ; + return true ; + case MPA_TOOLTIPFEED : + dVal = m_TParams.m_dTipFeed ; + return true ; + case MPA_TOOLOFFSR : + dVal = m_TParams.m_dOffsR ; + return true ; + case MPA_TOOLOFFSL : + dVal = m_TParams.m_dOffsL ; + return true ; + case MPA_SIDEANGLE : + dVal = m_Params.m_dSideAngle ; + return true ; + case MPA_APPROX : + dVal = m_Params.m_dApprox ; + return true ; + } + return false ; +} + + +//---------------------------------------------------------------------------- +bool +Sawing::GetParam( int nType, string& sVal) const +{ + switch ( nType) { + case MPA_NAME : + sVal = m_Params.m_sName ; + return true ; case MPA_TOOL : sVal = m_Params.m_sToolName ; - break ; + return true ; case MPA_DEPTH_STR : sVal = m_Params.m_sDepth ; - break ; - default : - return false ; + return true ; + case MPA_TUUID : + sVal = ToString( m_Params.m_ToolUuid) ; + return true ; + case MPA_UUID : + sVal = ToString( m_Params.m_Uuid) ; + return true ; } - return true ; + return false ; } //---------------------------------------------------------------------------- const ToolData& -Sawing::GetToolData( void) +Sawing::GetToolData( void) const { return m_TParams ; } diff --git a/Sawing.h b/Sawing.h index d978e0b..08e6efd 100644 --- a/Sawing.h +++ b/Sawing.h @@ -39,9 +39,11 @@ class Sawing : public Machining virtual bool SetParam( int nType, const std::string& sVal) ; virtual bool SetGeometry( const SELVECTOR& vIds) ; virtual bool Apply( void) ; - //virtual bool CalculateAxesValues( void) ; - virtual bool GetParam( int nType, std::string& sVal) ; - virtual const ToolData& GetToolData( void) ; + virtual bool GetParam( int nType, bool& bVal) const ; + virtual bool GetParam( int nType, int& nVal) const ; + virtual bool GetParam( int nType, double& dVal) const ; + virtual bool GetParam( int nType, std::string& sVal) const ; + virtual const ToolData& GetToolData( void) const ; virtual bool AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP) ; public : diff --git a/SawingData.cpp b/SawingData.cpp index f3ac327..f8a1df4 100644 --- a/SawingData.cpp +++ b/SawingData.cpp @@ -70,6 +70,10 @@ SawingData::Clone( void) const SawingData* pSdata = new(nothrow) SawingData ; // copio i dati if ( pSdata != nullptr) { + if ( ! pSdata->CopyFrom( this)) { + delete pSdata ; + return nullptr ; + } } return pSdata ; }