EgtMachKernel :

- migliorie e correzioni al DB lavorazioni.
This commit is contained in:
Dario Sassi
2015-11-15 08:35:42 +00:00
parent 7640eab85e
commit 052e1ba5e1
3 changed files with 67 additions and 22 deletions
+4 -4
View File
@@ -63,12 +63,12 @@ MachMgr::Clear( void)
{
// pulisco le macchine
while ( ! m_vMachines.empty()) {
if ( m_vMachines.back().pMachine != nullptr)
delete m_vMachines.back().pMachine ;
if ( m_vMachines.back().pTsMgr != nullptr)
delete m_vMachines.back().pTsMgr ;
if ( m_vMachines.back().pMsMgr != nullptr)
delete m_vMachines.back().pMsMgr ;
if ( m_vMachines.back().pTsMgr != nullptr)
delete m_vMachines.back().pTsMgr ;
if ( m_vMachines.back().pMachine != nullptr)
delete m_vMachines.back().pMachine ;
m_vMachines.pop_back() ;
}
// cancello simulatore, se necessario
+62 -17
View File
@@ -29,7 +29,10 @@ using namespace std ;
//----------------------------------------------------------------------------
const string MF_HEADER = "[HEADER]" ;
const string MF_VERSION = "VERSION" ;
const string MF_TOTAL = "TOTAL" ;
const string MF_SIZE = "SIZE" ;
const int MF_CURR_VER = 1001 ;
//----------------------------------------------------------------------------
@@ -102,8 +105,9 @@ MachiningsMgr::Load( const string& sMachsFile, const ToolsMgr* pTsMgr)
bool bEnd = false ;
// leggo l'intestazione
int nVersion = 0 ;
int nTotal = 0 ;
if ( ! LoadHeader( TheScanner, nTotal, bEnd)) {
if ( ! LoadHeader( TheScanner, nVersion, nTotal, bEnd)) {
bOk = false ;
string sOut = "LoadMachinings : Error on Header" ;
LOG_ERROR( GetEMkLogger(), sOut.c_str())
@@ -130,7 +134,7 @@ MachiningsMgr::Load( const string& sMachsFile, const ToolsMgr* pTsMgr)
//----------------------------------------------------------------------------
bool
MachiningsMgr::LoadHeader( Scanner& TheScanner, int& nTotal, bool& bEnd)
MachiningsMgr::LoadHeader( Scanner& TheScanner, int& nVersion, int& nTotal, bool& bEnd)
{
// leggo la prossima linea
string sLine ;
@@ -145,6 +149,7 @@ MachiningsMgr::LoadHeader( Scanner& TheScanner, int& nTotal, bool& bEnd)
bool bOk = true ;
// leggo le linee successive
bEnd = true ;
nVersion = 1000 ;
nTotal = 0 ;
while ( bOk && TheScanner.GetLine( sLine)) {
// se utensile successivo
@@ -157,7 +162,9 @@ MachiningsMgr::LoadHeader( Scanner& TheScanner, int& nTotal, bool& bEnd)
string sKey, sVal ;
SplitFirst( sLine, "=", sKey, sVal) ;
// riconosco la chiave
if ( ToUpper( sKey) == MF_TOTAL)
if ( ToUpper( sKey) == MF_VERSION)
bOk = FromString( sVal, nVersion) ;
else if ( ToUpper( sKey) == MF_TOTAL)
bOk = FromString( sVal, nTotal) ;
else
bOk = false ;
@@ -189,11 +196,25 @@ MachiningsMgr::LoadOneMachining( Scanner& TheScanner, bool& bEnd)
if ( IsNull( pMch))
return false ;
bool bOk = true ;
// imposto dimensione di default
int nSize = 0 ;
switch ( pMch->GetType()) {
case MT_DRILLING : nSize = 11 ; break ;
case MT_SAWING : nSize = 15 ; break ;
case MT_MILLING : nSize = 26 ; break ;
}
// eventuale lettura da file
if ( TheScanner.GetLine( sLine)) {
string sKey, sVal ;
SplitFirst( sLine, "=", sKey, sVal) ;
if ( ! (sKey == MF_SIZE && FromString( sVal, nSize)))
TheScanner.UngetLine( sLine) ;
}
// leggo i dati della lavorazione
bEnd = true ;
const int DIM_BS = 64 ;
bitset<DIM_BS> Flag ;
assert( pMch->GetSize() <= DIM_BS) ;
assert( nSize <= DIM_BS) ;
while ( bOk && TheScanner.GetLine( sLine)) {
// se lavorazione successiva
if ( sLine.front() == '[' && sLine.back() == ']') {
@@ -209,7 +230,7 @@ MachiningsMgr::LoadOneMachining( Scanner& TheScanner, bool& bEnd)
Flag.set( nKey) ;
}
// verifico di aver letto tutti i campi
bOk = bOk && ( Flag.count() == pMch->GetSize()) ;
bOk = bOk && ( Flag.count() == nSize) ;
// salvo i dati della lavorazione
bOk = bOk && m_umData.emplace( pMch->m_Uuid, Get( pMch)).second ;
bOk = bOk && m_suData.emplace( pMch->m_sName, pMch->m_Uuid).second ;
@@ -221,6 +242,10 @@ MachiningsMgr::LoadOneMachining( Scanner& TheScanner, bool& bEnd)
bool
MachiningsMgr::Save( bool bCompressed) const
{
// se non ci sono state modifiche, esco subito
if ( ! m_bModified)
return true ;
// faccio copia di backup del file originale
CopyFileEgt( m_sMachsFile, m_sMachsFile + ".bak") ;
@@ -264,6 +289,9 @@ MachiningsMgr::Save( bool bCompressed) const
// chiudo la scrittura
TheWriter.Close() ;
// dichiaro non più modificato rispetto al file
m_bModified = false ;
return true ;
}
@@ -276,6 +304,8 @@ MachiningsMgr::SaveHeader( Writer& TheWriter) const
string sOut ;
sOut = MF_HEADER ;
bOk = bOk && TheWriter.OutText( sOut) ;
sOut = MF_VERSION + "=" + ToString( MF_CURR_VER) ;
bOk = bOk && TheWriter.OutText( sOut) ;
sOut = MF_TOTAL + "=" + ToString( int( m_umData.size())) ;
bOk = bOk && TheWriter.OutText( sOut) ;
return bOk ;
@@ -293,6 +323,8 @@ MachiningsMgr::SaveOneMachining( const EgtUUID& Uuid, int& nCounter, Writer& The
// scrivo i dati della lavorazione
string sOut = "[" + pmData->GetTitle() + "_" + ToString( ++ nCounter, 3) + "]" ;
bool bOk = TheWriter.OutText( sOut) ;
sOut = MF_SIZE + "=" + ToString( pmData->GetSize()) ;
bOk = bOk && TheWriter.OutText( sOut) ;
for ( int i = 0 ; i < pmData->GetSize() ; ++ i) {
string sOut = pmData->ToString( i) ;
bOk = bOk && ! sOut.empty() && TheWriter.OutText( sOut) ;
@@ -341,10 +373,13 @@ MachiningsMgr::AddMachining( const string& sName, int nType)
// salvo i dati della lavorazione
bOk = bOk && m_umData.emplace( pMch->m_Uuid, Get( pMch)).second ;
bOk = bOk && m_suData.emplace( pMch->m_sName, pMch->m_Uuid).second ;
Release( pMch) ;
m_bModified = true ;
// la rendo la nuova lavorazione corrente
//m_tdCurrMach = pMch ;
if ( m_pCurrMach != nullptr)
delete m_pCurrMach ;
m_pCurrMach = pMch->Clone() ;
Release( pMch) ;
return bOk ;
}
@@ -370,11 +405,13 @@ MachiningsMgr::CopyMachining( const string& sSource, const string& sName)
// salvo i dati della lavorazione
bOk = bOk && m_umData.emplace( pMch->m_Uuid, Get( pMch)).second ;
bOk = bOk && m_suData.emplace( pMch->m_sName, pMch->m_Uuid).second ;
Release( pMch) ;
//m_bModified = true ;
m_bModified = true ;
// la rendo la nuova lavorazione corrente
//m_bCurrMach = true ;
//m_tdCurrMach = pMch ;
if ( m_pCurrMach != nullptr)
delete m_pCurrMach ;
m_pCurrMach = pMch->Clone() ;
Release( pMch) ;
return bOk ;
}
@@ -382,19 +419,26 @@ MachiningsMgr::CopyMachining( const string& sSource, const string& sName)
bool
MachiningsMgr::RemoveMachining( const string& sName)
{
// cerco l'utensile nell'elenco dei nomi
// cerco la lavorazione nell'elenco dei nomi e degli UUID
auto iNameIter = m_suData.find( sName) ;
if ( iNameIter == m_suData.end())
return true ;
auto iIter = m_umData.find( iNameIter->second) ;
// se era anche la lavorazione corrente, la resetto
//if ( m_bCurrMach && m_tdCurrMach.m_Uuid == iNameIter->second)
// m_bCurrMach = false ;
// rimuovo la lavorazione dal dizionario degli UUID
m_umData.erase( iNameIter->second) ;
if ( m_pCurrMach != nullptr && m_pCurrMach->m_Uuid == iNameIter->second) {
delete m_pCurrMach ;
m_pCurrMach = nullptr ;
}
if ( iIter != m_umData.end()) {
// libero la memoria della lavorazione
delete iIter->second ;
// rimuovo la lavorazione dal dizionario degli UUID
m_umData.erase( iIter) ;
}
// rimuovo la lavorazione dall'elenco dei nomi
m_suData.erase( iNameIter) ;
// dichiaro la modifica
//m_bModified = true ;
m_bModified = true ;
return true ;
}
@@ -511,6 +555,7 @@ MachiningsMgr::SaveCurrMachining( void)
}
}
// eseguo salvataggio
m_bModified = true ;
iIter->second->CopyFrom( m_pCurrMach) ;
return true ;
}
+1 -1
View File
@@ -50,7 +50,7 @@ class MachiningsMgr
private :
bool Clear( void) ;
bool LoadHeader( Scanner& TheScanner, int& nTotal, bool& bEnd) ;
bool LoadHeader( Scanner& TheScanner, int& nVersion, int& nTotal, bool& bEnd) ;
bool LoadOneMachining( Scanner& TheScanner, bool& bEnd) ;
bool SaveHeader( Writer& TheWriter) const ;
bool SaveOneMachining( const EgtUUID& Uuid, int& nCounter, Writer& TheWriter) const ;