//---------------------------------------------------------------------------- // 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 "Head.h" #include "Exit.h" #include "/EgtDev/Include/EMkToolConst.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EGnFileUtils.h" using namespace std ; //---------------------------------------------------------------------------- bool Machine::GetAllHeadsNames( STRVECTOR& vNames) const { // reset lista nomi vNames.clear() ; // ricerca delle teste for ( const auto& snGro : m_mapGroups) { if ( IsHeadGroup( snGro.second)) vNames.push_back( snGro.first) ; } // ordino alfabeticamente sort( vNames.begin(), vNames.end()) ; return true ; } //---------------------------------------------------------------------------- bool Machine::GetAllTcPosNames( STRVECTOR& vNames) const { // reset lista nomi vNames.clear() ; // ricerca delle posizioni di cambio utensile for ( const auto& snGro : m_mapGroups) { if ( IsTcPosGroup( snGro.second)) vNames.push_back( snGro.first) ; } // ordino alfabeticamente sort( vNames.begin(), vNames.end()) ; return true ; } //---------------------------------------------------------------------------- int Machine::GetHeadExitCount( const string& sHead) const { Head* pHead = GetHead( GetGroup( sHead)) ; return ( ( pHead != nullptr) ? pHead->GetExitCount() : 0) ; } //---------------------------------------------------------------------------- int Machine::GetHeadExitPosDirAux( const string& sHead, int nExit, Point3d& ptPos, Vector3d& vtDir, Vector3d& vtAux) const { if ( m_pGeomDB == nullptr) return false ; // recupero testa int nHeadId = GetGroup( sHead) ; Head* pHead = GetHead( nHeadId) ; if ( pHead == nullptr) return false ; // recupero uscita int nExitId = m_pGeomDB->GetFirstNameInGroup( nHeadId, MCH_EXIT + ToString( nExit)) ; Exit* pExit = GetExit( nExitId) ; if ( pExit == nullptr) return false ; // assegno i dati ptPos = pExit->GetPos() ; vtDir = pExit->GetTDir() ; vtAux = pHead->GetADir() ; return true ; } //---------------------------------------------------------------------------- int Machine::GetHeadSolCh( const string& sHead) const { // recupero testa Head* pHead = GetHead( GetGroup( sHead)) ; if ( pHead == nullptr) return MCH_SCC_NONE ; // recupero criterio di soluzione associato alla testa return pHead->GetSolCh() ; } //---------------------------------------------------------------------------- int Machine::GetHeadSelectType( const string& sHead) const { // recupero testa Head* pHead = GetHead( GetGroup( sHead)) ; if ( pHead == nullptr) return MCH_SCC_NONE ; // recupero tipo di selezione delle uscite della testa return pHead->GetSelectType() ; } //---------------------------------------------------------------------------- bool Machine::LoadTool( const string& sHead, int nExit, const string& sTool) { // controllo GeomDB if ( m_pGeomDB == nullptr) return false ; // recupero il gruppo dell' oggetto int nHdGrp = GetGroup( sHead) ; // se testa if ( IsHeadGroup( nHdGrp)) { // cerco il gruppo dell'uscita in quello della testa string sExit = MCH_EXIT + ToString( nExit) ; int nExGrp = m_pGeomDB->GetFirstNameInGroup( nHdGrp, sExit) ; Exit* pExit = GetExit( nExGrp) ; if ( pExit == nullptr) return false ; // inserisco l'utensile nell'uscita if ( ! LoadTool( pExit, sTool)) return false ; // abilito la testa return EnableHeadInSet( sHead) ; } // se posizione cambio utensile else if ( IsTcPosGroup( nHdGrp)) { // cerco il gruppo dell'uscita in quello della posizione cambio utensile string sExit = MCH_EXIT + ToString( nExit) ; int nExGrp = m_pGeomDB->GetFirstNameInGroup( nHdGrp, sExit) ; Exit* pExit = GetExit( nExGrp) ; if ( pExit == nullptr) return false ; // inserisco l'utensile nell'uscita if ( ! LoadTool( pExit, sTool)) return false ; // abilito la posizione cambio utensile return m_pGeomDB->SetStatus( nHdGrp, GDB_ST_ON) ; } // altrimenti errore return false ; } //---------------------------------------------------------------------------- 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 true ; // verifico esistenza file utensile string sDraw ; if ( ! m_pMchMgr->TdbSetCurrTool( sTool) || ! m_pMchMgr->TdbGetCurrToolParam( TPA_DRAW, sDraw)) return false ; string sToolFile = m_sMachineDir + "\\" + TOOLS_DIR + "\\" + sDraw ; if ( ! ExistsFile( sToolFile)) { string sOut = "Missing tool (" + sTool + ") draw : " + sToolFile ; LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; 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)) return false ; int nTGrpId = m_pGeomDB->GetFirstGroupInGroup( nExGrp) ; int nSolidId = m_pGeomDB->GetFirstNameInGroup( nTGrpId, "SOLID") ; if ( nSolidId == GDB_ID_NULL) return false ; // sposto eventuali info relative al porta utensile (ToolHolder) nel gruppo SOLID double dVal ; string sVal ; if ( m_pGeomDB->GetInfo( nTGrpId, TTH_BASE, dVal)) m_pGeomDB->SetInfo( nSolidId, TTH_BASE, dVal) ; if ( m_pGeomDB->GetInfo( nTGrpId, TTH_LEN, dVal)) m_pGeomDB->SetInfo( nSolidId, TTH_LEN, dVal) ; if ( m_pGeomDB->GetInfo( nTGrpId, TTH_DIAM, dVal)) m_pGeomDB->SetInfo( nSolidId, TTH_DIAM, dVal) ; if ( m_pGeomDB->GetInfo( nTGrpId, TTH_STEM_DIAM, dVal)) m_pGeomDB->SetInfo( nSolidId, TTH_STEM_DIAM, dVal) ; if ( m_pGeomDB->GetInfo( nTGrpId, TTH_TYPE, sVal)) m_pGeomDB->SetInfo( nSolidId, TTH_TYPE, sVal) ; // sposto il gruppo SOLID nell'uscita ed elimino la sua vecchia base m_pGeomDB->RelocateGlob( nSolidId, nExGrp, GDB_FIRST_SON) ; m_pGeomDB->Erase( nTGrpId) ; // rinomino il gruppo SOLID con il nome dell'utensile if ( ! m_pGeomDB->SetName( nSolidId, sTool)) { string sOut = "LoadTool error : " + sTool + " invalid name" ; LOG_ERROR( GetEMkLogger(), sOut.c_str()) return false ; } // lo ruoto 90 deg attorno alla X locale m_pGeomDB->Rotate( nSolidId, ORIG, X_AX, 0, 1) ; // se mortasa, lo ruoto 90 deg attorno a Z int nType ; if ( m_pMchMgr->TdbGetCurrToolParam( TPA_TYPE, nType) && nType == TT_MORTISE_STD) m_pGeomDB->Rotate( nSolidId, ORIG, Z_AX, 0, 1) ; pExit->SetTool( sTool) ; return true ; } //---------------------------------------------------------------------------- bool Machine::GetLoadedTool( const string& sHead, int nExit, string& sTool) const { // controllo GeomDB if ( m_pGeomDB == nullptr) return false ; // recupero il gruppo della testa int nHdGrp = GetGroup( sHead) ; if ( ! IsHeadGroup( nHdGrp)) return false ; // cerco il gruppo dell'uscita in quello della testa string sExit = MCH_EXIT + ToString( nExit) ; int nExGrp = m_pGeomDB->GetFirstNameInGroup( nHdGrp, sExit) ; Exit* pExit = GetExit( nExGrp) ; if ( pExit == nullptr) return false ; // recupero nome utensile montato sTool = pExit->GetTool() ; return ( ! sTool.empty()) ; } //---------------------------------------------------------------------------- bool Machine::UnloadTool( const string& sHead, int nExit) { // controllo GeomDB if ( m_pGeomDB == nullptr) return false ; // recupero il gruppo della testa o della posizione nel cambio utensili int nHdGrp = GetGroup( sHead) ; if ( ! IsHeadGroup( nHdGrp) && ! IsTcPosGroup( nHdGrp)) return false ; // cerco il gruppo dell'uscita in quello della testa string sExit = MCH_EXIT + ToString( nExit) ; int nExGrp = m_pGeomDB->GetFirstNameInGroup( nHdGrp, sExit) ; Exit* pExit = GetExit( nExGrp) ; if ( pExit == nullptr) return false ; // pulisco il gruppo dell'uscita m_pGeomDB->EmptyGroup( nExGrp) ; pExit->SetTool( "") ; return true ; } //---------------------------------------------------------------------------- bool Machine::LoadTools( const string& sHead, int nNoExit, int* pnCount) { // annullo eventuale parametro di conteggio if ( pnCount != nullptr) *pnCount = 0 ; // 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 int nHdGrp = GetGroup( sHead) ; Head* pHead = GetHead( nHdGrp) ; if ( pHead == nullptr) return false ; // ciclo su tutte le uscite for ( int nExit = 1 ; nExit <= pHead->GetExitCount() ; ++ nExit) { // se uscita da saltare, vado oltre if ( nExit == nNoExit) continue ; // 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()) { bool bOk = LoadTool( pExit, sTool) ; if ( bOk && pnCount != nullptr) ++ ( *pnCount) ; } // se nessun utensile, allora pulisco il gruppo dell'uscita else { m_pGeomDB->EmptyGroup( nExGrp) ; pExit->SetTool( "") ; } } // abilito la testa return EnableHeadInSet( sHead) ; } //---------------------------------------------------------------------------- bool Machine::LoadAllTools( void) { // 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 ; // ciclo su tutte le teste for ( const auto& snGro : m_mapGroups) { if ( IsHeadGroup( snGro.second)) { // recupero l'insieme di appartenenza della testa const STRVECTOR& vsHSet = GetHSet( snGro.first) ; if ( vsHSet.empty()) continue ; // se testa capofila dell'insieme if ( vsHSet.front() == snGro.first) { // carico prima testa con utensili dell'insieme for ( int i = 0, nTools = 0 ; i < int( vsHSet.size()) && nTools == 0 ; ++ i) { LoadTools( vsHSet[i], 0, &nTools) ; } } } } return true ; } //---------------------------------------------------------------------------- bool Machine::UnloadTools( const string& sHead) { // controllo GeomDB if ( m_pGeomDB == nullptr) return false ; // recupero la testa int nHdGrp = GetGroup( sHead) ; Head* pHead = GetHead( nHdGrp) ; if ( pHead == nullptr) return false ; // 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 ; // pulisco il gruppo dell'uscita m_pGeomDB->EmptyGroup( nExGrp) ; pExit->SetTool( "") ; } return true ; } //---------------------------------------------------------------------------- bool Machine::UnloadAllTools( void) { // controllo GeomDB if ( m_pGeomDB == nullptr) return false ; // ciclo su tutte le teste bool bOk = true ; for ( const auto& snGro : m_mapGroups) { if ( IsHeadGroup( snGro.second)) { if ( ! UnloadTools( snGro.first)) bOk = false ; } } return bOk ; } //---------------------------------------------------------------------------- bool Machine::ResetHeadSet( const string& sHead) { // controllo GeomDB if ( m_pGeomDB == nullptr) return false ; // recupero il set della testa const STRVECTOR& vsHSet = GetHSet( sHead) ; if ( vsHSet.empty()) return false ; // ciclo su tutte le teste dell'insieme per svuotarle bool bOk = true ; for ( size_t i = 0 ; i < vsHSet.size() ; ++ i) { if ( ! UnloadTools( vsHSet[i])) bOk = false ; // visualizzo solo la prima testa m_pGeomDB->SetMode( GetGroup( sHead), ( i == 0 ? GDB_MD_STD : GDB_MD_HIDDEN)) ; } return bOk ; }