From 03dd454ef9ba7bf7586ec2c8ddf638a2c24f9187 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Thu, 19 Jan 2017 11:32:39 +0000 Subject: [PATCH] EgtMachKernel : - aggiunta gestione attrezzaggio anche in simulazione - in ToolDeselect aggiunto nome prossimo utensile EMT.NEXTTOOL. --- Generator.cpp | 10 ++++++---- Generator.h | 2 +- OutputConst.h | 1 + Simulator.cpp | 33 +++++++++++++++++++++++---------- Simulator.h | 4 +++- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/Generator.cpp b/Generator.cpp index 1688b7c..3bcfee1 100644 --- a/Generator.cpp +++ b/Generator.cpp @@ -177,7 +177,7 @@ Generator::ProcessDisposition( int nOpId, int nOpInd) // Se utensile cambierà if ( ! m_sTool.empty() && m_sTool != sTool) { // emetto deselezione vecchio utensile - if ( ! OnToolDeselect( sHead, nExit, sTcPos)) + if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos)) return false ; } // Aggiorno utensile e assi macchina @@ -286,7 +286,7 @@ Generator::ProcessMachining( int nOpId, int nOpInd) m_pMchMgr->TdbSetCurrTool( m_sTool) ; } // emetto deselezione vecchio utensile - if ( ! OnToolDeselect( sNextHead, nNextExit, sNextTcPos)) + if ( ! OnToolDeselect( sTool, sNextHead, nNextExit, sNextTcPos)) return false ; } // Aggiorno utensile e assi macchina @@ -781,10 +781,12 @@ Generator::OnToolSelect( const string& sTool, const string& sHead, int nExit, co //---------------------------------------------------------------------------- bool -Generator::OnToolDeselect( const string& sNextHead, int nNextExit, const string& sNextTcPos) +Generator::OnToolDeselect( const std::string& sNextTool, const string& sNextHead, int nNextExit, const string& sNextTcPos) { + // assegno il prossimo utensile + bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTTOOL, sNextTool) ; // assegno la prossima testa - bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTHEAD, sNextHead) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTHEAD, sNextHead) ; // assegno la prossima uscita bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTEXIT, nNextExit) ; // assegno l'eventuale prossima posizione nel TC diff --git a/Generator.h b/Generator.h index b1258b4..c6133e9 100644 --- a/Generator.h +++ b/Generator.h @@ -43,7 +43,7 @@ class Generator bool OnProgramEnd( void) ; bool ProcessToolData( void) ; bool OnToolSelect( const std::string& sTool, const std::string& sHead, int nExit, const std::string& sTcPos) ; - bool OnToolDeselect( const std::string& sNextHead, int nNextExit, const std::string& sNextTcPos) ; + bool OnToolDeselect( const std::string& sNextTool, const std::string& sNextHead, int nNextExit, const std::string& sNextTcPos) ; bool OnDispositionStart( int nOpId, int nOpInd, int nPhase, bool bEmpty, bool bSomeByHand) ; bool OnDispositionEnd( void) ; bool OnTableData( const std::string& sName, const Point3d& ptOri1) ; diff --git a/OutputConst.h b/OutputConst.h index f5ce097..58a90e6 100644 --- a/OutputConst.h +++ b/OutputConst.h @@ -60,6 +60,7 @@ static const std::string GVAR_TCOMP = ".TCOMP" ; // (int) numero cor static const std::string GVAR_TDIAM = ".TDIAM" ; // (num) diametro utensile static const std::string GVAR_TLEN = ".TLEN" ; // (num) lunghezza utensile static const std::string GVAR_SMAX = ".SMAX" ; // (num) massima speed utensile +static const std::string GVAR_NEXTTOOL = ".NEXTTOOL" ; // (string) nome del prossimo utensile static const std::string GVAR_NEXTHEAD = ".NEXTHEAD" ; // (string) nome testa del prossimo utensile static const std::string GVAR_NEXTEXIT = ".NEXTEXIT" ; // (int) indice uscita su testa del prox utensile static const std::string GVAR_NEXTTCPOS = ".NEXTTCPOS" ; // (string) eventuale posizione del prox utensile nel TC diff --git a/Simulator.cpp b/Simulator.cpp index cc46534..5225ad6 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -77,6 +77,10 @@ Simulator::Start( void) if ( m_pMchMgr == nullptr || m_pMchMgr->GetCurrMachGroup() == GDB_ID_NULL) return false ; + // recupero eventuale attrezzaggio della macchinata + m_stuMgr.Init( m_pMchMgr) ; + m_stuMgr.Load() ; + // Reset utensile e assi correnti m_sTool.clear() ; ResetAxes() ; @@ -301,15 +305,20 @@ Simulator::UpdateTool( bool bForced) if ( ! pMch->GetParam( MPA_TUUID, sTuuid) || ! m_pMchMgr->TdbGetToolFromUUID( sTuuid, sTool)) return false ; - if ( ! m_pMchMgr->TdbSetCurrTool( sTool)) - return false ; - string sHead ; m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ; - int nExit ; m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ; - string sTcPos ; m_pMchMgr->TdbGetCurrToolParam( TPA_TCPOS, sTcPos) ; + string sTcPos ; string sHead ; int nExit ; + if ( ! m_stuMgr.GetToolData( sTool, sTcPos, sHead, nExit)) { + if ( m_pMchMgr->TdbSetCurrTool( sTool)) { + m_pMchMgr->TdbGetCurrToolParam( TPA_TCPOS, sTcPos) ; + m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ; + m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ; + } + // ripristino l'utensile corrente + m_pMchMgr->TdbSetCurrTool( m_sTool) ; + } // se cambierà e non forzato (inizio), scarico l'utensile corrente if ( sTool != m_sTool && ! bForced) { // eventuale lancio script per scarico utensile - if ( ! OnToolDeselect( sHead, nExit, sTcPos)) + if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos)) return false ; } // se cambiato oppure forzato, attivo l'utensile della lavorazione @@ -317,7 +326,7 @@ Simulator::UpdateTool( bool bForced) // se forzato, pulisco la testa if ( bForced) m_pMchMgr->ResetHeadSet( sHead) ; - // carico l'utensile + // carico l'utensile (e lo rendo corrente) if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) return false ; m_sTool = sTool ; @@ -337,7 +346,7 @@ Simulator::UpdateTool( bool bForced) string sTool ; string sHead ; int nExit ; string sTcPos ; pDisp->GetToolData( sTool, sHead, nExit, sTcPos) ; // eventuale lancio script per scarico utensile - if ( ! OnToolDeselect( sHead, nExit, sTcPos)) + if ( ! OnToolDeselect( sTool, sHead, nExit, sTcPos)) return false ; // carico l'utensile if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) @@ -449,6 +458,8 @@ Simulator::FindAndManageOperationStart( bool bFirst, int& nStatus) return false ; } ++ m_nOpInd ; + // imposto la lavorazione come corrente + m_pMchMgr->SetCurrMachining( m_nOpId) ; // richiamo gestione evento inizio lavorazione if ( ! OnMachiningStart( m_nOpId, m_nOpInd)) { nStatus = MCH_SIM_ERR ; @@ -882,10 +893,12 @@ Simulator::OnToolSelect( const string& sTool, const string& sHead, int nExit, co //---------------------------------------------------------------------------- bool -Simulator::OnToolDeselect( const string& sNextHead, int nNextExit, const string& sNextTcPos) +Simulator::OnToolDeselect( const std::string& sNextTool, const string& sNextHead, int nNextExit, const string& sNextTcPos) { + // assegno il prossimo utensile + bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTTOOL, sNextTool) ; // assegno la prossima testa - bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTHEAD, sNextHead) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTHEAD, sNextHead) ; // assegno la prossima uscita bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_NEXTEXIT, nNextExit) ; // assegno l'eventuale prossima posizione nel TC diff --git a/Simulator.h b/Simulator.h index 8628f59..728cf5f 100644 --- a/Simulator.h +++ b/Simulator.h @@ -14,6 +14,7 @@ #pragma once #include "CamData.h" +#include "SetupMgr.h" #include "/EgtDev/Include/EMkSimuGenConst.h" class MachMgr ; @@ -57,7 +58,7 @@ class Simulator const std::string& sTable, const Point3d& ptOri1, bool bEmpty) ; bool OnDispositionEnd( void) ; bool OnToolSelect( const std::string& sTool, const std::string& sHead, int nExit, const std::string& sTcPos) ; - bool OnToolDeselect( const std::string& sNextHead, int nNextExit, const std::string& sNextTcPos) ; + bool OnToolDeselect( const std::string& sNextTool, const std::string& sNextHead, int nNextExit, const std::string& sNextTcPos) ; bool OnMachiningStart( int nOpId, int nOpInd) ; bool OnMachiningEnd( void) ; bool OnPathStartAux( int nInd, const std::string& sAS) ; @@ -73,6 +74,7 @@ class Simulator MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni IGeomDB* m_pGeomDB ; // puntatore al DB geometrico Machine* m_pMachine ; // puntatore alla macchina + SetupMgr m_stuMgr ; // gestore dell'attrezzaggio double m_dStep ; // lunghezza di riferimento per la velocità di simulazione int m_nOpId ; // identificativo della operazione (lavoraz.) corrente int m_nOpInd ; // contatore della operazione (lavoraz.) corrente