a90a7ad34a
- al salvataggio DB utensili si scaricano tutti gli utensili dalle teste della macchina (se necessari verranno ricaricati con le eventuali nuove geometrie).
270 lines
8.6 KiB
C++
270 lines
8.6 KiB
C++
//----------------------------------------------------------------------------
|
|
// 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 each ( const auto& snGro in m_mapGroups) {
|
|
if ( IsHeadGroup( snGro.second))
|
|
vNames.push_back( snGro.first) ;
|
|
}
|
|
// ordino alfabeticamente
|
|
std::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) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Machine::LoadTool( const string& sHead, int nExit, const string& sTool)
|
|
{
|
|
// 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 ;
|
|
// 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 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 ;
|
|
m_pGeomDB->RelocateGlob( nSolidId, nExGrp, GDB_FIRST_SON) ;
|
|
m_pGeomDB->Erase( nTGrpId) ;
|
|
if ( ! m_pGeomDB->SetName( nSolidId, sTool)) {
|
|
string sOut = "LoadTool error : " + sTool + " invalid name" ;
|
|
LOG_INFO( GetEMkLogger(), sOut.c_str())
|
|
return false ;
|
|
}
|
|
// lo ruoto 90 deg attorno alla X locale
|
|
int nT = m_pGeomDB->GetFirstGroupInGroup( nExGrp) ;
|
|
if ( nT == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->Rotate( nT, ORIG, X_AX, 90) ;
|
|
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
|
|
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 ;
|
|
// pulisco il gruppo dell'uscita
|
|
m_pGeomDB->EmptyGroup( nExGrp) ;
|
|
pExit->SetTool( "") ;
|
|
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
|
|
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 ;
|
|
// 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::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 each ( const auto& snGro in 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 ;
|
|
}
|