Files
EgtMachKernel/MachMgrBasic.cpp
T
Dario Sassi ec420de8ef EgtMachKernel 1.6e1 :
- aggiunta prima versione di caricamento delle macchine.
2015-05-04 07:33:53 +00:00

246 lines
7.9 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : MachMgr.cpp Data : 16.04.15 Versione : 1.6d3
// Contenuto : Implementazione delle funzionalità base della classe MachMgr.
//
//
//
// Modifiche : 16.04.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "DllMain.h"
#include "MachMgr.h"
#include "MachConst.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EgnFileUtils.h"
#include "/EgtDev/Include/EgtKeyCodes.h"
#include "/EgtDev/Include/SELkKeyProc.h"
#include <new>
using namespace std ;
//----------------------------------------------------------------------------
IMachMgr*
CreateMachMgr( void)
{
// verifico la chiave e le opzioni
unsigned int nOpt1, nOpt2 ;
int nOptExpDays ;
int nRet = GetKeyOptions( GetEMkKey(), KEY_BASELIB_PROD, KEY_BASELIB_VER, KEY_BASELIB_LEV,
nOpt1, nOpt2, nOptExpDays) ;
if ( nRet != KEY_OK) {
string sErr = "Error on Key (MKC/" + ToString( nRet) + ")" ;
LOG_ERROR( GetEMkLogger(), sErr.c_str()) ;
return false ;
}
if ( (nOpt1 & KEYOPT_EMK_BASE) == 0 || nOptExpDays < GetCurrDay()) {
string sErr = "Error on Key (MKC/OPT)" ;
LOG_ERROR( GetEMkLogger(), sErr.c_str()) ;
return false ;
}
// creo il MachMgr
return static_cast<IMachMgr*> ( new(nothrow) MachMgr) ;
}
//----------------------------------------------------------------------------
// MachMgr
//----------------------------------------------------------------------------
MachMgr::MachMgr( void)
{
m_pGeomDB = nullptr ;
m_nMachBaseId = GDB_ID_NULL ;
m_nMachAuxId = GDB_ID_NULL ;
m_nCurrMGrpId = GDB_ID_NULL ;
m_nCurrMGeoId = GDB_ID_NULL ;
}
//----------------------------------------------------------------------------
bool
MachMgr::Init( IGeomDB* pGeomDB, const string& sMachinesDir)
{
m_pGeomDB = pGeomDB ;
m_sMachinesDir = sMachinesDir ;
m_nMachBaseId = GDB_ID_NULL ;
m_nMachAuxId = GDB_ID_NULL ;
m_nCurrMGrpId = GDB_ID_NULL ;
m_nCurrMGeoId = GDB_ID_NULL ;
return ( m_pGeomDB != nullptr && ExistsDirectory( m_sMachinesDir)) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::Update( void)
{
// ricerca del gruppo base per le lavorazioni
m_nMachBaseId = FindMachBase( GDB_ID_ROOT) ;
// imposto gruppo di lavorazione corrente a nessuno
m_nCurrMGrpId = GDB_ID_NULL ;
// verifico i gruppi di lavorazione
int nId = m_pGeomDB->GetFirstGroupInGroup( m_nMachBaseId) ;
while ( nId != GDB_ID_NULL) {
// recupero successivo
int nNextId = m_pGeomDB->GetNextGroup( nId) ;
// se non è gruppo di lavoro, lo elimino
MachGrp mgData ;
if ( ! VerifyMachGroup( nId, mgData))
m_pGeomDB->Erase( nId) ;
// passo al successivo
nId = nNextId ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
MachMgr::Insert( int nInsGrp)
{
// cerco MachBase nel gruppo di inserimento
int nInsMachBaseId = FindMachBase( nInsGrp) ;
if ( nInsMachBaseId == GDB_ID_NULL)
return true ;
// verifica ed eventuale creazione del gruppo base per le lavorazioni
if ( ! CreateMachBase())
return false ;
// ciclo sui suoi gruppi
int nId = m_pGeomDB->GetFirstGroupInGroup( nInsMachBaseId) ;
while ( nId != GDB_ID_NULL) {
// prossimo gruppo
int nNextId = m_pGeomDB->GetNextGroup( nId) ;
// se gruppo di lavoro
MachGrp mgData ;
if ( VerifyMachGroup( nId, mgData)) {
// recupero il nome e se già presente lo modifico
string sName ;
if ( ! m_pGeomDB->GetName( nId, sName) ||
! GetMachGroupNewName( sName) ||
! m_pGeomDB->SetName( nId, sName))
return false ;
// sposto il gruppo
if ( ! m_pGeomDB->Relocate( nId, m_nMachBaseId, GDB_LAST_SON))
return false ;
}
// passo al prossimo
nId = nNextId ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
MachMgr::IsMachBase( int nId) const
{
int nLevel ;
std::string sName ;
return ( m_pGeomDB != nullptr &&
m_pGeomDB->GetLevel( nId, nLevel) && nLevel == GDB_LV_SYSTEM &&
m_pGeomDB->GetName( nId, sName) && sName == MACH_BASE) ;
}
//----------------------------------------------------------------------------
int
MachMgr::FindMachBase( int nGroup) const
{
// verifica collegamento a DB geometrico
if ( m_pGeomDB == nullptr)
return GDB_ID_NULL ;
// cerco il gruppo di base delle macchinate nel gruppo passato
int nId = m_pGeomDB->GetFirstGroupInGroup( nGroup) ;
while ( nId != GDB_ID_NULL) {
// verifico se gruppo cercato
if ( IsMachBase( nId))
return nId ;
// passo al successivo
nId = m_pGeomDB->GetNextGroup( nId) ;
}
return GDB_ID_NULL ;
}
//----------------------------------------------------------------------------
bool
MachMgr::VerifyMachBase( void) const
{
// verifica collegamento a DB geometrico
if ( m_pGeomDB == nullptr)
return false ;
// verifica validità indice del gruppo base
if ( m_nMachBaseId == GDB_ID_NULL)
return false ;
// verifica esistenza gruppo di base per macchinate
if ( ! IsMachBase( m_nMachBaseId)) {
const_cast<int&>( m_nMachBaseId) = GDB_ID_NULL ;
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
MachMgr::CreateMachBase( void)
{
// se già esiste, esco con successo
if ( VerifyMachBase())
return true ;
// non trovato, devo creare il gruppo di base delle lavorazioni
m_nMachBaseId = m_pGeomDB->InsertGroup( GDB_ID_NULL, GDB_ID_ROOT, GDB_FIRST_SON, GLOB_FRM) ;
if ( m_nMachBaseId == GDB_ID_NULL)
return false ;
// imposto nome del gruppo
m_pGeomDB->SetName( m_nMachBaseId, MACH_BASE) ;
// imposto livello del gruppo a System
m_pGeomDB->SetLevel( m_nMachBaseId, GDB_LV_SYSTEM) ;
return true ;
}
//----------------------------------------------------------------------------
bool
MachMgr::IsMachAux( int nId) const
{
int nLevel ;
std::string sName ;
return ( m_pGeomDB != nullptr &&
m_pGeomDB->GetLevel( nId, nLevel) && nLevel == GDB_LV_TEMP &&
m_pGeomDB->GetName( nId, sName) && sName == MACH_AUX) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::VerifyMachAux( void) const
{
// verifica collegamento a DB geometrico
if ( m_pGeomDB == nullptr)
return false ;
// verifica validità indice del gruppo base
if ( m_nMachAuxId == GDB_ID_NULL)
return false ;
// verifica esistenza gruppo di base per macchinate
if ( ! IsMachAux( m_nMachAuxId)) {
const_cast<int&>( m_nMachAuxId) = GDB_ID_NULL ;
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
MachMgr::CreateMachAux( void)
{
// se già esiste, esco con successo
if ( VerifyMachAux())
return true ;
// non trovato, devo creare il gruppo di base delle lavorazioni
m_nMachAuxId = m_pGeomDB->InsertGroup( GDB_ID_NULL, GDB_ID_ROOT, GDB_FIRST_SON, GLOB_FRM) ;
if ( m_nMachAuxId == GDB_ID_NULL)
return false ;
// imposto nome del gruppo
m_pGeomDB->SetName( m_nMachAuxId, MACH_AUX) ;
// imposto livello del gruppo a Temp
m_pGeomDB->SetLevel( m_nMachAuxId, GDB_LV_TEMP) ;
return true ;
}