diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 22f3368..e39bef3 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/Generator.cpp b/Generator.cpp index 9e23126..dd5686f 100644 --- a/Generator.cpp +++ b/Generator.cpp @@ -83,8 +83,7 @@ Generator::Run( const string& sCncFile, const std::string& sInfo) return false ; // recupero eventuale attrezzaggio della macchinata - m_stuMgr.Init( m_pMchMgr) ; - m_stuMgr.Load() ; + m_pMchMgr->UpdateSetup() ; // evento inizio esecuzione bool bOk = true ; @@ -94,7 +93,7 @@ Generator::Run( const string& sCncFile, const std::string& sInfo) } // apertura file di output ed evento inizio programma - if ( bOk && ! OnProgramStart( m_pMachine->GetMachineName(), sCncFile, sInfo, m_stuMgr.Exists())) { + if ( bOk && ! OnProgramStart( m_pMachine->GetMachineName(), sCncFile, sInfo, m_pMchMgr->GetCurrSetupMgr().Exists())) { bOk = false ; LOG_INFO( GetEMkLogger(), "OnProgramStart error") ; } @@ -276,7 +275,7 @@ Generator::ProcessMachining( int nOpId, int nOpInd) if ( ! m_sTool.empty() && m_sTool != sTool) { // recupero la testa del prossimo utensile (prima dall'attrezzaggio, poi dal DB utensili) string sNextTcPos ; string sNextHead ; int nNextExit ; - if ( ! m_stuMgr.GetToolData( sTool, sNextTcPos, sNextHead, nNextExit)) { + if ( ! m_pMchMgr->GetCurrSetupMgr().GetToolData( sTool, sNextTcPos, sNextHead, nNextExit)) { if ( m_pMchMgr->TdbSetCurrTool( sTool)) { m_pMchMgr->TdbGetCurrToolParam( TPA_TCPOS, sNextTcPos) ; m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sNextHead) ; @@ -295,7 +294,7 @@ Generator::ProcessMachining( int nOpId, int nOpInd) // Se utensile cambiato, emetto selezione nuovo utensile if ( m_sTool != m_sPrevTool) { string sTcPos ; string sHead ; int nExit ; - if ( ! m_stuMgr.GetToolData( m_sTool, sTcPos, sHead, nExit)) { + if ( ! m_pMchMgr->GetCurrSetupMgr().GetToolData( m_sTool, sTcPos, sHead, nExit)) { m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ; m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ; m_pMchMgr->TdbGetCurrToolParam( TPA_TCPOS, sTcPos) ; @@ -445,7 +444,7 @@ Generator::UpdateTool( const string& sTool) return false ; // lo carico in macchina (se esiste attrezzaggio prendo i dati da questo) string sTcPos ; string sHead ; int nExit ; - if ( ! m_stuMgr.GetToolData( sTool, sTcPos, sHead, nExit)) { + if ( ! m_pMchMgr->GetCurrSetupMgr().GetToolData( sTool, sTcPos, sHead, nExit)) { m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ; m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ; } @@ -600,10 +599,10 @@ Generator::ProcessToolData( void) bool bOk = true ; // se definito attrezzaggio - if ( m_stuMgr.Exists()) { + if ( m_pMchMgr->GetCurrSetupMgr().Exists()) { // verifico che tutti gli utensili siano attrezzati for ( size_t i = 0 ; i < vTdata.size() ; ++ i) { - if ( ! m_stuMgr.FindTool( vTdata[i].sName)) { + if ( ! m_pMchMgr->GetCurrSetupMgr().FindTool( vTdata[i].sName)) { string sErr = "Error : " + vTdata[i].sName + " missing in setup " ; LOG_INFO( GetEMkLogger(), sErr.c_str()) bOk = false ; @@ -611,7 +610,7 @@ Generator::ProcessToolData( void) } // emetto l'elenco di tutti gli utensili attrezzati string sTcPos ; string sHead ; int nExit ; string sTool ; - for ( int i = 1 ; m_stuMgr.GetPosData( i, sTcPos, sHead , nExit, sTool); ++ i) { + for ( int i = 1 ; m_pMchMgr->GetCurrSetupMgr().GetPosData( i, sTcPos, sHead , nExit, sTool); ++ i) { // se nella posizione non c'è utensile, vado oltre if ( sTool.empty()) continue ; diff --git a/Generator.h b/Generator.h index c6133e9..e6c2e36 100644 --- a/Generator.h +++ b/Generator.h @@ -14,7 +14,6 @@ #pragma once #include "CamData.h" -#include "SetupMgr.h" class MachMgr ; class IGeomDB ; @@ -67,7 +66,6 @@ class Generator 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 std::string m_sPrevTool ; // nome dell'utensile precedente std::string m_sTool ; // nome dell'utensile corrente STRVECTOR m_AxesName ; // nomi degli assi macchina attivi diff --git a/MachMgr.h b/MachMgr.h index 93b25e6..72afa31 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -17,6 +17,7 @@ #include "Machine.h" #include "ToolsMgr.h" #include "MachiningsMgr.h" +#include "SetupMgr.h" #include "Simulator.h" #include "/EgtDev/Include/EMkMachMgr.h" #include "/EgtDev/Include/EgtNumCollection.h" @@ -169,6 +170,7 @@ class MachMgr : public IMachMgr bool GetDefaultSetupName( std::string& sName) const override ; bool ImportSetup( const std::string& sName) override ; bool VerifyCurrSetup( STRVECTOR& vsErrors) override ; + bool UpdateSetup( void) override ; // Machinings DataBase bool MdbGetMachiningNewName( std::string& sName) const override ; bool MdbAddMachining( const std::string& sName, int nType) ; @@ -345,6 +347,9 @@ class MachMgr : public IMachMgr bool VerifyFixtureInGroup( int nFxtId, bool bLinkedAllowed = true) const ; bool GetFixturePhases( int nFxtId, INTVECTOR& vPhase) const ; int GetUnusedFixture( const string& sName, int nPhase) ; + // Setup + SetupMgr& GetCurrSetupMgr( void) const + { return const_cast( m_stuMgr) ; } // Machines Machine* GetCurrMachine( void) const ; ToolsMgr* GetCurrToolsMgr( void) const ; @@ -416,6 +421,7 @@ class MachMgr : public IMachMgr MachGrp m_cCurrMGrp ; // dati principali macchinata corrente int m_nCurrMch ; // indice macchina corrente (0-based) MCHDATAVECTOR m_vMachines ; // elenco macchine caricate + SetupMgr m_stuMgr ; // gestore attrezzaggio macchinata corrente int m_nPhasesCount ; // numero fasi di lavorazione della macchinata corrente int m_nCurrPhase ; // indice fase corrente (1-based) int m_nCurrDispId ; // identificativo della disposizione corrente diff --git a/MachMgrBasic.cpp b/MachMgrBasic.cpp index 03334d7..8315463 100644 --- a/MachMgrBasic.cpp +++ b/MachMgrBasic.cpp @@ -101,6 +101,7 @@ MachMgr::Init( const string& sMachinesDir, IGeomDB* pGeomDB, m_nMachAuxId = GDB_ID_NULL ; m_nCurrMGrpId = GDB_ID_NULL ; m_nCurrMch = - 1 ; + m_stuMgr.Reset() ; return ( m_nContextId > 0 && m_pGeomDB != nullptr && ExistsDirectory( m_sMachinesDir)) ; } diff --git a/MachMgrMachGroups.cpp b/MachMgrMachGroups.cpp index cb87c9e..b7e2fd0 100644 --- a/MachMgrMachGroups.cpp +++ b/MachMgrMachGroups.cpp @@ -334,6 +334,8 @@ MachMgr::PrepareCurrMachGroup( int nId) m_nCurrMGrpId = nId ; m_cCurrMGrp = mgData ; m_nCurrMch = GetMachine( m_cCurrMGrp.MGeoName) ; + m_stuMgr.Init( this) ; + m_stuMgr.Load() ; m_nPhasesCount = CalcPhaseCount() ; m_nCurrPhase = 0 ; m_nCurrDispId = GDB_ID_NULL ; diff --git a/MachMgrSetup.cpp b/MachMgrSetup.cpp index 68645eb..62f1cd3 100644 --- a/MachMgrSetup.cpp +++ b/MachMgrSetup.cpp @@ -63,16 +63,12 @@ MachMgr::ImportSetup( const string& sName) sFileName += sDefault + "." + SETUP_EXT ; } - // gestione attrezzaggio - SetupMgr stuMgr ; - stuMgr.Init( this) ; - // importo l'attrezzaggio - if ( ! stuMgr.Import( sFileName)) + if ( ! m_stuMgr.Import( sFileName)) return false ; // lo inserisco nel progetto - return stuMgr.Save() ; + return m_stuMgr.Save() ; } //---------------------------------------------------------------------------- @@ -82,11 +78,6 @@ MachMgr::VerifyCurrSetup( STRVECTOR& vsErrors) // pulizia vettore degli utensili mancanti vsErrors.clear() ; - // recupero attrezzaggio corrente - SetupMgr stuMgr ; - if ( ! stuMgr.Init( this) || ! stuMgr.Load()) - return false ; - // ciclo sulle lavorazioni della macchinata corrente per ricavare gli utensili utilizzati int nOpId = GetFirstActiveOperation() ; while ( nOpId != GDB_ID_NULL) { @@ -108,7 +99,7 @@ MachMgr::VerifyCurrSetup( STRVECTOR& vsErrors) vsErrors.push_back( sErr) ; } // Se utensile non attrezzato - if ( ! stuMgr.FindTool( sTool)) { + if ( ! m_stuMgr.FindTool( sTool)) { // se non presente nella lista dei non attrezzati, lo aggiungo if ( find( vsErrors.begin(), vsErrors.end(), sTool) == vsErrors.end()) vsErrors.push_back( sTool) ; @@ -120,3 +111,10 @@ MachMgr::VerifyCurrSetup( STRVECTOR& vsErrors) return vsErrors.empty() ; } + +//---------------------------------------------------------------------------- +bool +MachMgr::UpdateSetup( void) +{ + return m_stuMgr.Load() ; +} diff --git a/Machine.h b/Machine.h index a66dab8..9ff585a 100644 --- a/Machine.h +++ b/Machine.h @@ -58,6 +58,7 @@ class Machine bool LoadTool( const std::string& sHead, int nExit, const std::string& sTool) ; bool GetLoadedTool( const std::string& sHead, int nExit, std::string& sTool) const ; bool UnloadTool( const string& sHead, int nExit) ; + bool LoadTools( const string& sHead) ; bool ResetHeadSet( const std::string& sHead) ; bool GetAxisToken( const std::string& sAxis, std::string& sToken) const ; bool GetAxisInvert( const std::string& sAxis, bool& bInvert) const ; @@ -184,6 +185,7 @@ class Machine bool AddHeadToSet( const std::string& sHSet, const std::string& sName) ; const STRVECTOR& GetHSet( const std::string& sHead) const ; bool EnableHeadInSet( const std::string& sHead) ; + bool LoadTool( Exit* pExit, const std::string& sTool) ; bool AdjustExitFrames( int nLay, const MUEXITVECTOR& vMuExit, const Vector3d& vtADir) ; bool CreateExitGroups( int nLay, const MUEXITVECTOR& vMuExit) ; bool CalculateKinematicChain( void) ; diff --git a/MachineHeads.cpp b/MachineHeads.cpp index 6985669..6a77d20 100644 --- a/MachineHeads.cpp +++ b/MachineHeads.cpp @@ -64,9 +64,23 @@ Machine::LoadTool( const string& sHead, int nExit, const string& sTool) Exit* pExit = GetExit( nExGrp) ; if ( pExit == nullptr) return false ; - // se utensile già montato, abilito ed esco + // inserisco l'utensile nell'uscita + if ( ! LoadTool( pExit, sTool)) + return false ; + // abilito la testa + return EnableHeadInSet( sHead) ; +} + +//---------------------------------------------------------------------------- +bool +Machine::LoadTool( Exit* pExit, const string& sTool) +{ + // controllo GeomDB e Exit + if ( m_pGeomDB == nullptr || pExit == nullptr) + return false ; + // se utensile già montato, esco if ( sTool == pExit->GetTool()) - return EnableHeadInSet( sHead) ; + return true ; // verifico esistenza file utensile string sDraw ; if ( ! m_pMchMgr->TdbSetCurrTool( sTool) || ! m_pMchMgr->TdbGetCurrToolParam( TPA_DRAW, sDraw)) @@ -78,6 +92,7 @@ Machine::LoadTool( const string& sHead, int nExit, const string& sTool) return false ; } // pulisco il gruppo dell'uscita + int nExGrp = pExit->GetOwner() ; m_pGeomDB->EmptyGroup( nExGrp) ; // inserisco l'utensile nel gruppo if ( ! m_pGeomDB->Load( sToolFile, nExGrp)) @@ -99,7 +114,7 @@ Machine::LoadTool( const string& sHead, int nExit, const string& sTool) return false ; m_pGeomDB->Rotate( nT, ORIG, X_AX, 90) ; pExit->SetTool( sTool) ; - return EnableHeadInSet( sHead) ; + return true ; } //---------------------------------------------------------------------------- @@ -147,6 +162,45 @@ Machine::UnloadTool( const string& sHead, int nExit) return true ; } +//---------------------------------------------------------------------------- +bool +Machine::LoadTools( const string& sHead) +{ + // controllo GeomDB e MachMgr + if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr) + return false ; + // verifico che l'attrezzaggio contenga qualcosa + if ( ! m_pMchMgr->GetCurrSetupMgr().Exists()) + return true ; + // recupero la testa + Head* pHead = GetHead( GetGroup( sHead)) ; + if ( pHead == nullptr) + return false ; + int nHdGrp = pHead->GetOwner() ; + // ciclo su tutte le uscite + for ( int nExit = 1 ; nExit <= pHead->GetExitCount() ; ++ nExit) { + // recupero l'uscita + string sExit = MCH_EXIT + ToString( nExit) ; + int nExGrp = m_pGeomDB->GetFirstNameInGroup( nHdGrp, sExit) ; + Exit* pExit = GetExit( nExGrp) ; + if ( pExit == nullptr) + continue ; + // recupero l'utensile da attrezzare sull'uscita + string sTool ; + if ( m_pMchMgr->GetCurrSetupMgr().GetToolName( sHead, nExit, sTool) && ! sTool.empty()) { + LoadTool( pExit, sTool) ; + } + // se nessun utensile, allora pulisco il gruppo dell'uscita + else { + m_pGeomDB->EmptyGroup( nExGrp) ; + pExit->SetTool( "") ; + } + } + + // abilito la testa + return EnableHeadInSet( sHead) ; +} + //---------------------------------------------------------------------------- bool Machine::ResetHeadSet( const string& sHead) @@ -179,7 +233,6 @@ Machine::ResetHeadSet( const string& sHead) } // visualizzo solo la prima testa m_pGeomDB->SetMode( nHdGrp, ( i == 0 ? GDB_MD_STD : GDB_MD_HIDDEN)) ; - //m_pGeomDB->SetStatus( nHdGrp, ( i == 0 ? GDB_ST_ON : GDB_ST_OFF)) ; } return true ; -} \ No newline at end of file +} diff --git a/SetupMgr.cpp b/SetupMgr.cpp index 3999035..f9f9a04 100644 --- a/SetupMgr.cpp +++ b/SetupMgr.cpp @@ -44,6 +44,17 @@ SetupMgr::Init( MachMgr* pMchMgr) return true ; } +//---------------------------------------------------------------------------- +bool +SetupMgr::Reset( void) +{ + m_vStuData.clear() ; + m_pMchMgr = nullptr ; + m_pGeomDB = nullptr ; + m_pMachine = nullptr ; + return true ; +} + //---------------------------------------------------------------------------- bool SetupMgr::Load( void) @@ -218,7 +229,7 @@ SetupMgr::Import( const string& sFileName) //---------------------------------------------------------------------------- bool -SetupMgr::FindTool( const string& sName) +SetupMgr::FindTool( const string& sName) const { // verifico validità utensile if ( IsEmptyOrSpaces( sName)) @@ -233,7 +244,7 @@ SetupMgr::FindTool( const string& sName) //---------------------------------------------------------------------------- bool -SetupMgr::GetPosData( int nPos, string& sTcPos, string& sHead, int& nExit, string& sName) +SetupMgr::GetPosData( int nPos, string& sTcPos, string& sHead, int& nExit, string& sName) const { // verifico che la posizione sia valida int nI = nPos - 1 ; @@ -256,7 +267,7 @@ SetupMgr::GetPosData( int nPos, string& sTcPos, string& sHead, int& nExit, strin //---------------------------------------------------------------------------- bool -SetupMgr::GetToolData( const string& sName, string& sTcPos, string& sHead, int& nExit, int* pnPos) +SetupMgr::GetToolData( const string& sName, string& sTcPos, string& sHead, int& nExit, int* pnPos) const { // verifico validità utensile if ( IsEmptyOrSpaces( sName)) @@ -279,3 +290,18 @@ SetupMgr::GetToolData( const string& sName, string& sTcPos, string& sHead, int& *pnPos = nI + 1 ; return true ; } + +//---------------------------------------------------------------------------- +bool +SetupMgr::GetToolName( const string& sHead, int nExit, string& sName) const +{ + // eseguo ricerca + for ( size_t i = 0 ; i < m_vStuData.size() ; ++ i) { + if ( EqualNoCase( sHead, m_vStuData[i].m_sHead) && m_vStuData[i].m_nExit == nExit) { + sName = m_vStuData[i].m_sName ; + return true ; + } + } + sName.clear() ; + return false ; +} diff --git a/SetupMgr.h b/SetupMgr.h index f2cc78f..d187906 100644 --- a/SetupMgr.h +++ b/SetupMgr.h @@ -40,14 +40,16 @@ class SetupMgr public : SetupMgr( void) ; bool Init( MachMgr* pMchMgr) ; + bool Reset( void) ; bool Load( void) ; bool Save( void) const ; bool Import( const std::string& sFileName) ; - bool Exists( void) + bool Exists( void) const { return ! m_vStuData.empty() ; } - bool FindTool( const std::string& sName) ; - bool GetPosData( int nPos, std::string& sTcPos, std::string& sHead, int& nExit, std::string& sName) ; - bool GetToolData( const std::string& sName, std::string& sTcPos, std::string& sHead, int& nExit, int* pnPos = nullptr) ; + bool FindTool( const std::string& sName) const ; + bool GetPosData( int nPos, std::string& sTcPos, std::string& sHead, int& nExit, std::string& sName) const ; + bool GetToolData( const std::string& sName, std::string& sTcPos, std::string& sHead, int& nExit, int* pnPos = nullptr) const ; + bool GetToolName( const std::string& sHead, int nExit, std::string& sName) const ; private : typedef std::vector< SetupData> STUDVECTOR ; diff --git a/Simulator.cpp b/Simulator.cpp index 3c14362..5fd8997 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -78,9 +78,8 @@ 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() ; + // forzo aggiornamento attrezzaggio della macchinata + m_pMchMgr->UpdateSetup() ; // Reset utensile e assi correnti m_sTool.clear() ; @@ -298,7 +297,7 @@ Simulator::UpdateTool( bool bForced) ! m_pMchMgr->TdbGetToolFromUUID( sTuuid, sTool)) return false ; string sTcPos ; string sHead ; int nExit ; - if ( ! m_stuMgr.GetToolData( sTool, sTcPos, sHead, nExit)) { + if ( ! m_pMchMgr->GetCurrSetupMgr().GetToolData( sTool, sTcPos, sHead, nExit)) { if ( m_pMchMgr->TdbSetCurrTool( sTool)) { m_pMchMgr->TdbGetCurrToolParam( TPA_TCPOS, sTcPos) ; m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ; @@ -318,6 +317,8 @@ Simulator::UpdateTool( bool bForced) // se forzato, pulisco la testa if ( bForced) m_pMchMgr->ResetHeadSet( sHead) ; + // carico tutti gli utensili attrezzati + m_pMachine->LoadTools( sHead) ; // carico l'utensile (e lo rendo corrente) if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) return false ; diff --git a/Simulator.h b/Simulator.h index b5f3c19..14073d7 100644 --- a/Simulator.h +++ b/Simulator.h @@ -14,7 +14,6 @@ #pragma once #include "CamData.h" -#include "SetupMgr.h" #include "/EgtDev/Include/EMkSimuGenConst.h" class MachMgr ; @@ -74,7 +73,6 @@ 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