EgtMachKernel 1.6j4 :

- modifiche a DB utensili per gestione utensile corrente
- prima versione generatore codice.
This commit is contained in:
Dario Sassi
2015-10-31 09:45:57 +00:00
parent a4525dd059
commit 2324a8b3f4
22 changed files with 835 additions and 184 deletions
+158 -39
View File
@@ -33,25 +33,36 @@ const string TF_TOTAL = "TOTAL" ;
ToolsMgr::ToolsMgr( void)
{
m_suCIter = m_suData.cend() ;
m_nCounter = 0 ;
m_bCurrTool = false ;
m_bModified = false ;
}
//----------------------------------------------------------------------------
bool
ToolsMgr::Init( const string& sToolsFile)
ToolsMgr::Clear( void)
{
// salvo la path del file con i dati
m_sToolsFile = sToolsFile ;
// log
string sOut = "ToolsMgr Init : " + m_sToolsFile ;
LOG_INFO( GetEMkLogger(), sOut.c_str())
// pulisco le raccolte
m_suData.clear() ;
m_utData.clear() ;
// reinizializzo stato
m_suCIter = m_suData.cend() ;
m_bCurrTool = false ;
m_bModified = false ;
return true ;
}
//----------------------------------------------------------------------------
bool
ToolsMgr::Load( void)
ToolsMgr::Load( const string& sToolsFile)
{
// pulisco
Clear() ;
// salvo la path del file con i dati
m_sToolsFile = sToolsFile ;
{ string sOut = "ToolsMgr Init : " + m_sToolsFile ;
LOG_INFO( GetEMkLogger(), sOut.c_str()) }
// inizializzo lo scanner
Scanner TheScanner ;
if ( ! TheScanner.Init( m_sToolsFile, ";")) {
@@ -182,6 +193,10 @@ ToolsMgr::LoadOneTool( Scanner& TheScanner, bool& bEnd)
bool
ToolsMgr::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_sToolsFile, m_sToolsFile + ".bak") ;
@@ -206,10 +221,10 @@ ToolsMgr::Save( bool bCompressed) const
}
// ciclo su tutti i nomi degli utensili
m_nCounter = 0 ;
int nCounter = 0 ;
for ( auto iIter = m_suData.cbegin() ; iIter != m_suData.cend() ; ++ iIter) {
// salvo l'utensile
if ( ! SaveOneTool( iIter->second, TheWriter)) {
if ( ! SaveOneTool( iIter->second, nCounter, TheWriter)) {
string sOut = "SaveTools : Error on tool " + iIter->first ;
LOG_ERROR( GetEMkLogger(), sOut.c_str())
return false ;
@@ -225,6 +240,9 @@ ToolsMgr::Save( bool bCompressed) const
// chiudo la scrittura
TheWriter.Close() ;
// dichiaro non più modificato rispetto al file
m_bModified = false ;
return true ;
}
@@ -244,7 +262,7 @@ ToolsMgr::SaveHeader( Writer& TheWriter) const
//----------------------------------------------------------------------------
bool
ToolsMgr::SaveOneTool( const EgtUUID& Uuid, Writer& TheWriter) const
ToolsMgr::SaveOneTool( const EgtUUID& Uuid, int& nCounter, Writer& TheWriter) const
{
// recupero i dati dell'utensile
auto iIter = m_utData.find( Uuid) ;
@@ -252,7 +270,7 @@ ToolsMgr::SaveOneTool( const EgtUUID& Uuid, Writer& TheWriter) const
return false ;
const ToolData& tData = iIter->second ;
// scrivo i dati dell'utensile
string sOut = "[TOOL_" + ToString( ++ m_nCounter, 3) + "]" ;
string sOut = "[TOOL_" + ToString( ++ nCounter, 3) + "]" ;
bool bOk = TheWriter.OutText( sOut) ;
for ( int i = 0 ; i < tData.GetSize() ; ++ i) {
string sOut = tData.ToString( i) ;
@@ -261,6 +279,26 @@ ToolsMgr::SaveOneTool( const EgtUUID& Uuid, Writer& TheWriter) const
return bOk ;
}
//----------------------------------------------------------------------------
bool
ToolsMgr::GetToolNewName( string& sName) const
{
// il parametro nome deve essere valido
if ( &sName == nullptr)
return false ;
// se nome vuoto, assegno radice standard
if ( sName.empty())
sName = "Tool" ;
// verifico che il nome sia unico
int nCount = 1 ;
string sOrigName = sName ;
while ( GetTool( sName) != nullptr) {
++ nCount ;
sName = sOrigName + "_" + ToString( nCount) ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
ToolsMgr::AddTool( const string& sName, int nType)
@@ -277,8 +315,14 @@ ToolsMgr::AddTool( const string& sName, int nType)
tData.m_nType = nType ;
CreateEgtUUID( tData.m_Uuid) ;
// salvo i dati dell'utensile
return ( m_utData.emplace( tData.m_Uuid, tData).second &&
m_suData.emplace( tData.m_sName, tData.m_Uuid).second) ;
if ( ! m_utData.emplace( tData.m_Uuid, tData).second ||
! m_suData.emplace( tData.m_sName, tData.m_Uuid).second)
return false ;
m_bModified = true ;
// lo rendo il nuovo utensile corrente
m_bCurrTool = true ;
m_tdCurrTool = tData ;
return true ;
}
//----------------------------------------------------------------------------
@@ -298,8 +342,14 @@ ToolsMgr::CopyTool( const std::string& sSource, const std::string& sName)
tData.m_sName = sName ;
CreateEgtUUID( tData.m_Uuid) ;
// salvo i dati del nuovo utensile
return ( m_utData.emplace( tData.m_Uuid, tData).second &&
m_suData.emplace( tData.m_sName, tData.m_Uuid).second) ;
m_bModified = true ;
if ( ! m_utData.emplace( tData.m_Uuid, tData).second ||
! m_suData.emplace( tData.m_sName, tData.m_Uuid).second)
return false ;
// lo rendo il nuovo utensile corrente
m_bCurrTool = true ;
m_tdCurrTool = tData ;
return true ;
}
//----------------------------------------------------------------------------
@@ -310,33 +360,18 @@ ToolsMgr::RemoveTool( const string& sName)
auto iNameIter = m_suData.find( sName) ;
if ( iNameIter == m_suData.end())
return true ;
// se era anche l'utensile corrente, lo resetto
if ( m_bCurrTool && m_tdCurrTool.m_Uuid == iNameIter->second)
m_bCurrTool = false ;
// rimuovo l'utensile dal dizionario degli UUID
m_utData.erase( iNameIter->second) ;
// rimuovo l'utensile dall'elenco dei nomi
m_suData.erase( iNameIter) ;
// dichiaro la modifica
m_bModified = true ;
return true ;
}
//----------------------------------------------------------------------------
ToolData*
ToolsMgr::GetTool( const EgtUUID& Uuid)
{
auto iIter = m_utData.find( Uuid) ;
if ( iIter == m_utData.end())
return nullptr ;
return &( iIter->second) ;
}
//----------------------------------------------------------------------------
ToolData*
ToolsMgr::GetTool( const string& sName)
{
auto iIter = m_suData.find( sName) ;
if ( iIter == m_suData.end())
return nullptr ;
return GetTool( iIter->second) ;
}
//----------------------------------------------------------------------------
const ToolData*
ToolsMgr::GetTool( const EgtUUID& Uuid) const
@@ -364,7 +399,7 @@ ToolsMgr::GetFirstTool( int nFamily, string& sName, int& nType) const
// primo nome
m_suCIter = m_suData.begin() ;
// lo verifico
if ( VerifyCurrTool( nFamily, sName, nType))
if ( VerifyTool( nFamily, sName, nType))
return true ;
// continuo ricerca
return GetNextTool( nFamily, sName, nType) ;
@@ -379,7 +414,7 @@ ToolsMgr::GetNextTool( int nFamily, string& sName, int& nType) const
// nome successivo
++ m_suCIter ;
// lo verifico
if ( VerifyCurrTool( nFamily, sName, nType))
if ( VerifyTool( nFamily, sName, nType))
return true ;
}
// non trovato
@@ -388,7 +423,7 @@ ToolsMgr::GetNextTool( int nFamily, string& sName, int& nType) const
//----------------------------------------------------------------------------
bool
ToolsMgr::VerifyCurrTool( int nFamily, string& sName, int& nType) const
ToolsMgr::VerifyTool( int nFamily, string& sName, int& nType) const
{
// il corrente deve esistere
if ( m_suCIter == m_suData.end())
@@ -407,3 +442,87 @@ ToolsMgr::VerifyCurrTool( int nFamily, string& sName, int& nType) const
}
return false ;
}
//----------------------------------------------------------------------------
bool
ToolsMgr::SetCurrTool( const std::string& sName)
{
// recupero i dati dell'utensile
const ToolData* ptData = GetTool( sName) ;
if ( ptData == nullptr) {
m_bCurrTool = false ;
return false ;
}
// li salvo come correnti
m_bCurrTool = true ;
m_tdCurrTool = *ptData ;
return true ;
}
//----------------------------------------------------------------------------
bool
ToolsMgr::SaveCurrTool( void)
{
// verifico validità utensile corrente
if ( ! m_bCurrTool)
return false ;
// recupero puntatore a utensile corrente nel DB
auto iIter = m_utData.find( m_tdCurrTool.m_Uuid) ;
if ( iIter == m_utData.end())
return false ;
// eseguo salvataggio
m_bModified = true ;
iIter->second = m_tdCurrTool ;
return true ;
}
//----------------------------------------------------------------------------
bool
ToolsMgr::SetCurrToolParam( int nType, int nVal)
{
return ( m_bCurrTool ? m_tdCurrTool.SetParam( nType, nVal) : false) ;
}
//----------------------------------------------------------------------------
bool
ToolsMgr::SetCurrToolParam( int nType, double dVal)
{
return ( m_bCurrTool ? m_tdCurrTool.SetParam( nType, dVal) : false) ;
}
//----------------------------------------------------------------------------
bool
ToolsMgr::SetCurrToolParam( int nType, const string& sVal)
{
// non è possibile cambiare UUID
if ( nType == TPA_UUID)
return false ;
// è possibile cambiare il nome, solo se il nuovo non è già presente nel DB
if ( nType == TPA_NAME) {
if ( GetTool( sVal) != nullptr)
return false ;
}
// eseguo
return ( m_bCurrTool ? m_tdCurrTool.SetParam( nType, sVal) : false) ;
}
//----------------------------------------------------------------------------
bool
ToolsMgr::GetCurrToolParam( int nType, int& nVal) const
{
return ( m_bCurrTool ? m_tdCurrTool.GetParam( nType, nVal) : false) ;
}
//----------------------------------------------------------------------------
bool
ToolsMgr::GetCurrToolParam( int nType, double& dVal) const
{
return ( m_bCurrTool ? m_tdCurrTool.GetParam( nType, dVal) : false) ;
}
//----------------------------------------------------------------------------
bool
ToolsMgr::GetCurrToolParam( int nType, string& sVal) const
{
return ( m_bCurrTool ? m_tdCurrTool.GetParam( nType, sVal) : false) ;
}