diff --git a/Disposition.cpp b/Disposition.cpp index 9b056cd..7a7effa 100644 --- a/Disposition.cpp +++ b/Disposition.cpp @@ -44,6 +44,7 @@ static std::string DIS_MVD_FLAG = "MvF" ; static std::string DIS_NUM = "NUM" ; static std::string DIS_HEAD = "Head" ; static std::string DIS_EXIT = "Exit" ; +static std::string DIS_TCPOS = "TcPos" ; static std::string DIS_SOMEBYHAND = "Sbh" ; //---------------------------------------------------------------------------- static double DISP_BOX_TOL = - 0.5 ; @@ -74,6 +75,7 @@ Disposition::Clone( void) const pDisp->m_vMvrData = m_vMvrData ; pDisp->m_sHead = m_sHead ; pDisp->m_nExit = m_nExit ; + pDisp->m_sTcPos = m_sTcPos ; pDisp->m_nShifts = m_nShifts ; pDisp->m_bSomeByHand = m_bSomeByHand ; } @@ -122,6 +124,7 @@ Disposition::Dump( string& sOut, bool bMM, const char* szNewLine) const sOut += "Num=" + ToString( m_nShifts) + szNewLine ; sOut += "Head=" + m_sHead + szNewLine ; sOut += "Exit=" + ToString( m_nExit) + szNewLine ; + sOut += "TcPos=" + m_sTcPos + szNewLine ; sOut += "ByHand=" + ToString( m_bSomeByHand) + szNewLine ; return true ; } @@ -136,7 +139,7 @@ Disposition::Save( STRVECTOR& vString) const int nFxdLines = 1 + 4 * nFxdTot ; int nMvdTot = int( m_vMvrData.size()) ; int nMvdLines = 1 + 4 * nMvdTot ; - int nOther = 4 ; + int nOther = 5 ; vString.insert( vString.begin(), 4 + nFxdLines + nMvdLines + nOther, "") ; // Nome if ( ! SetVal( DIS_TABLE, m_sTabName, vString[++k])) @@ -179,6 +182,8 @@ Disposition::Save( STRVECTOR& vString) const return false ; if ( ! SetVal( DIS_SOMEBYHAND, m_bSomeByHand, vString[++k])) return false ; + if ( ! SetVal( DIS_TCPOS, m_sTcPos, vString[++k])) + return false ; } catch( ...) { return false ; } return true ; @@ -257,6 +262,10 @@ Disposition::Load( const STRVECTOR& vString, int nBaseGdbId) if ( ! GetVal( vString[++k], DIS_SOMEBYHAND, m_bSomeByHand)) return false ; } + if ( k + 1 < int( vString.size())) { + if ( ! GetVal( vString[++k], DIS_TCPOS, m_sTcPos)) + return false ; + } return true ; } @@ -1005,16 +1014,12 @@ bool Disposition::SpecialApply( bool bRecalc) { // reset - m_sHead.empty() ; + m_sHead.clear() ; m_nExit = 0 ; m_nShifts = 0 ; - // verifico tavola - if ( ! m_bTabOk && ! SetTable( m_sTabName)) - return false ; - // recupero la macchina corrente - Machine* pMch = m_pMchMgr->GetCurrMachine() ; - if ( pMch == nullptr) - return false ; + m_bSomeByHand = false ; + m_sTcPos.clear() ; + // costanti static const string EMC_VAR = "EMC" ; // tabella variabili locali per calcolo static const string EVAR_TABNAME = ".TABNAME" ; // IN (string) nome della tavola macchina @@ -1027,10 +1032,17 @@ Disposition::SpecialApply( bool bRecalc) static const string EVAR_SBH = ".SBH" ; // OUT (bool) flag presenza operazioni manuali static const string ON_SPECIAL_APPLY = "OnSpecialApplyDisposition" ; + // recupero la macchina corrente + Machine* pMch = m_pMchMgr->GetCurrMachine() ; + if ( pMch == nullptr) + return false ; + // eseguo l'azione if ( pMch->LuaExistsFunction( ON_SPECIAL_APPLY)) { bool bOk = true ; int nErr = 99 ; + // verifico tavola + bOk = ( m_bTabOk || SetTable( m_sTabName)) ; // imposto valori parametri bOk = bOk && pMch->LuaCreateGlobTable( EMC_VAR) ; bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_TABNAME, m_sTabName) ; @@ -1044,8 +1056,8 @@ Disposition::SpecialApply( bool bRecalc) bOk = bOk && pMch->LuaGetGlobVar( EMC_VAR + EVAR_SHIFTS, m_nShifts) ; bOk = bOk && pMch->LuaGetGlobVar( EMC_VAR + EVAR_SBH, m_bSomeByHand) ; // recupero valori parametri opzionali - if ( ! pMch->LuaGetGlobVar( EMC_VAR + EVAR_TCPOS, m_sTcPos)) - m_sTcPos.clear() ; + if ( bOk) + pMch->LuaGetGlobVar( EMC_VAR + EVAR_TCPOS, m_sTcPos) ; // reset bOk = bOk && pMch->LuaResetGlobVar( EMC_VAR) ; // segnalo errori diff --git a/Drilling.cpp b/Drilling.cpp index ff27fde..9af43fa 100644 --- a/Drilling.cpp +++ b/Drilling.cpp @@ -475,6 +475,10 @@ Drilling::Apply( bool bRecalc) if ( ! AdjustStartEndMovements()) return false ; + // esecuzione eventuale personalizzazioni + if ( ! PostApply()) + return false ; + return true ; } diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 5324f35..5b68460 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/Machine.h b/Machine.h index 024941f..6eb1667 100644 --- a/Machine.h +++ b/Machine.h @@ -247,6 +247,7 @@ class Machine static int LuaEmtAddRapidStart( lua_State* L) ; static int LuaEmtAddRapidMove( lua_State* L) ; static int LuaEmtAddLinearMove( lua_State* L) ; + static int LuaEmtGetAxesPos( lua_State* L) ; static int LuaEmtLinkRawPartToGroup( lua_State* L) ; static int LuaEmtUnlinkRawPartFromGroup( lua_State* L) ; static int LuaEmtUnlinkAllRawPartsFromGroups( lua_State* L) ; diff --git a/MachineLua.cpp b/MachineLua.cpp index 48ca9e2..8926f8c 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -95,6 +95,8 @@ Machine::LuaInit( const string& sMachineName) m_LuaMgr.RegisterFunction( "EmtAddRapidStart", Machine::LuaEmtAddRapidStart) ; m_LuaMgr.RegisterFunction( "EmtAddRapidMove", Machine::LuaEmtAddRapidMove) ; m_LuaMgr.RegisterFunction( "EmtAddLinearMove", Machine::LuaEmtAddLinearMove) ; + // registro le funzioni di lettura entità CL per lua + m_LuaMgr.RegisterFunction( "EmtGetAxesPos", Machine::LuaEmtGetAxesPos) ; // registro le funzioni di scrittura part program per lua m_LuaMgr.RegisterFunction( "EmtWrite", Machine::LuaEmtWrite) ; diff --git a/MachineLuaCL.cpp b/MachineLuaCL.cpp index f24097b..cbb1129 100644 --- a/MachineLuaCL.cpp +++ b/MachineLuaCL.cpp @@ -190,3 +190,29 @@ Machine::LuaEmtAddLinearMove( lua_State* L) LuaSetParam( L) ; return 1 ; } + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtGetAxesPos( lua_State* L) +{ + // 1 parametri : nClEntId + int nClEntId ; + LuaCheckParam( L, 1, nClEntId) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva valida + if ( m_pMchLua == nullptr || + m_pMchLua->m_pMchMgr == nullptr || m_pMchLua->m_pGeomDB == nullptr) + return luaL_error( L, " Unknown Machine") ; + // recupero l'oggetto CamData + const CamData* pCamData = GetCamData( m_pMchLua->m_pGeomDB->GetUserObj( nClEntId)) ; + bool bOk = ( pCamData != nullptr) ; + bOk = bOk && pCamData->GetAxesStatus() == CamData::AS_OK ; + if ( bOk) { + DBLVECTOR AxesVal = pCamData->GetAxesVal() ; + LuaSetParam( L, AxesVal) ; + } + else + LuaSetParam( L) ; + + return 1 ; +} \ No newline at end of file diff --git a/Machining.cpp b/Machining.cpp index 157bb22..bf6064c 100644 --- a/Machining.cpp +++ b/Machining.cpp @@ -70,3 +70,46 @@ Machining:: NeedPrevHome( void) const { return false ; } + +//---------------------------------------------------------------------------- +bool +Machining::PostApply( void) +{ + // recupero la macchina corrente + Machine* pMch = m_pMchMgr->GetCurrMachine() ; + if ( pMch == nullptr) + return false ; + // costanti + static const string EMC_VAR = "EMC" ; // tabella variabili locali per calcolo + static const string EVAR_PHASE = ".PHASE" ; // IN (int) indice fase + static const string EVAR_MCHID = ".MCHID" ; // IN (int) identificativo della lavorazione + static const string EVAR_ERROR = ".ERR" ; // OUT (int) codice di errore ( 0 = ok) + static const string ON_POST_APPLY = "OnPostApplyMachining" ; + + // eseguo l'azione + if ( pMch->LuaExistsFunction( ON_POST_APPLY)) { + bool bOk = true ; + int nErr = 99 ; + // imposto valori parametri + bOk = bOk && pMch->LuaCreateGlobTable( EMC_VAR) ; + bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_PHASE, m_nPhase) ; + bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_MCHID, m_nOwnerId) ; + // eseguo + bOk = bOk && pMch->LuaCallFunction( ON_POST_APPLY) ; + // recupero valori parametri obbligatori + bOk = bOk && pMch->LuaGetGlobVar( EMC_VAR + EVAR_ERROR, nErr) ; + // recupero valori parametri opzionali + // ... + // reset + bOk = bOk && pMch->LuaResetGlobVar( EMC_VAR) ; + // segnalo errori + if ( nErr != 0) { + bOk = false ; + string sOut = " Error in " + ON_POST_APPLY + " (" + ToString( nErr) + ")" ; + LOG_INFO( GetEMkLogger(), sOut.c_str()) + } + return bOk ; + } + else + return true ; +} \ No newline at end of file diff --git a/Machining.h b/Machining.h index 3e944f4..0c6a87b 100644 --- a/Machining.h +++ b/Machining.h @@ -42,6 +42,9 @@ class Machining : public Operation virtual const ToolData& GetToolData( void) const = 0 ; virtual bool GetGeometry( SELVECTOR& vIds) const = 0 ; + public : + bool PostApply( void) ; + protected : Machining( void) ; } ; diff --git a/Milling.cpp b/Milling.cpp index fc7b936..acc6033 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -520,6 +520,10 @@ Milling::Apply( bool bRecalc) if ( ! AdjustStartEndMovements()) return false ; + // esecuzione eventuale personalizzazioni + if ( ! PostApply()) + return false ; + return true ; } diff --git a/SawFinishing.cpp b/SawFinishing.cpp index b7b9317..26e7e6f 100644 --- a/SawFinishing.cpp +++ b/SawFinishing.cpp @@ -451,6 +451,10 @@ SawFinishing::Apply( bool bRecalc) if ( ! AdjustStartEndMovements()) return false ; + // esecuzione eventuale personalizzazioni + if ( ! PostApply()) + return false ; + return true ; } diff --git a/SawRoughing.cpp b/SawRoughing.cpp index 32962c9..6555acf 100644 --- a/SawRoughing.cpp +++ b/SawRoughing.cpp @@ -430,6 +430,10 @@ SawRoughing::Apply( bool bRecalc) if ( ! AdjustStartEndMovements()) return false ; + // esecuzione eventuale personalizzazioni + if ( ! PostApply()) + return false ; + return true ; } diff --git a/Sawing.cpp b/Sawing.cpp index 32cf2dd..6601692 100644 --- a/Sawing.cpp +++ b/Sawing.cpp @@ -537,6 +537,10 @@ Sawing::Apply( bool bRecalc) if ( ! AdjustStartEndMovements()) return false ; + // esecuzione eventuale personalizzazioni + if ( ! PostApply()) + return false ; + return true ; } diff --git a/Simulator.cpp b/Simulator.cpp index 495c433..0d68608 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -657,6 +657,20 @@ Simulator::UpdateAxesPos( void) return true ; } +//---------------------------------------------------------------------------- +bool +Simulator::ResetAuxAxes( void) +{ + // pulisco dati assi ausiliari + m_AuxAxesName.clear() ; + m_AuxAxesToken.clear() ; + m_AuxAxesInvert.clear() ; + m_AuxAxesLinear.clear() ; + m_AuxAxesVal.clear() ; + m_AuxAxesEnd.clear() ; + return true ; +} + //---------------------------------------------------------------------------- bool Simulator::OnOperationEnd( void) @@ -868,14 +882,6 @@ Simulator::OnPathEnd( void) bool Simulator::OnMoveStart( const CamData* pCamData) { - // pulisco dati assi ausiliari - m_AuxAxesName.clear() ; - m_AuxAxesToken.clear() ; - m_AuxAxesInvert.clear() ; - m_AuxAxesLinear.clear() ; - m_AuxAxesVal.clear() ; - m_AuxAxesEnd.clear() ; - // recupero e assegno i dati // dati generali bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MOVEID, m_nEntId) ; @@ -899,16 +905,23 @@ Simulator::OnMoveStart( const CamData* pCamData) bOk = bOk && m_pMachine->LuaResetGlobVar( GLOB_VAR + GVAR_AUXAXES) ; // verifico esistenza funzione - if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MOVE_START)) + if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MOVE_START)) { + ResetAuxAxes() ; return bOk ; + } // chiamo la funzione bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_MOVE_START) ; - if ( ! bOk) + if ( ! bOk) { + ResetAuxAxes() ; return false ; + } // forzo aggiornamento posizione assi (possono essere stati mossi nello script) UpdateAxesPos() ; + // reset assi ausiliari + ResetAuxAxes() ; + // recupero i dati di ritorno int nNumAuxAxes = 0 ; if ( ! m_pMachine->LuaGetGlobVar( GLOB_VAR + GVAR_AUXAXES, nNumAuxAxes) || nNumAuxAxes == 0) diff --git a/Simulator.h b/Simulator.h index c58d6c4..9a37755 100644 --- a/Simulator.h +++ b/Simulator.h @@ -40,6 +40,7 @@ class Simulator bool UpdateTool( bool bForced = false) ; bool UpdateAxes( void) ; bool UpdateAxesPos( void) ; + bool ResetAuxAxes( void) ; private : bool OnOperationEnd( void) ;