Files
EgtMachKernel/ToolsMgr.h
T
Dario Sassi 82f3d1a5d8 EgtMachKernel 2.2c1 :
- in Milling modificato riconoscimento percorso chiuso per cambio inizio (per evitare percorsi sovrapposti di pulizia spigoli)
- in Milling, Pocketing, Mortising e Chiseling corretto cambio affondamento che supera l'elevazione
- in gestione utensili aggiunte funzioni SetCurrToolValInNotes, RemoveCurrToolValInNotes e GetCurrToolValInNotes.
2020-03-07 08:59:15 +00:00

151 lines
5.8 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : ToolsMgr.h Data : 01.06.15 Versione : 1.6f1
// Contenuto : Dichiarazione della classe ToolsMgr.
//
//
//
// Modifiche : 01.06.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include "ToolData.h"
#include "/EgtDEv/Include/EmkToolConst.h"
#include "/EgtDev/Include/EGnStringKeyVal.h"
#include <unordered_map>
#include <map>
class Scanner ;
class Writer ;
//----------------------------------------------------------------------------
class ToolsMgr
{
public :
ToolsMgr( void) ;
bool Load( const std::string& sToolsDir, const std::string& sToolsFile) ;
bool Reload( void) ;
bool GetModified( void) const
{ return m_bModified ; }
const UUIDVECTOR& GetUtModified( void) const
{ return m_utModified ; }
bool Save( bool bCompressed = true) const ;
bool GetToolNewName( std::string& sName) const ;
bool AddTool( const std::string& sName, int nType) ;
bool CopyTool( const std::string& sSource, const std::string& sName) ;
bool RemoveTool( const std::string& sName) ;
const ToolData* GetTool( const EgtUUID& Uuid) const ;
const ToolData* GetTool( const std::string& sName) const ;
bool GetFirstTool( int nFamily, std::string& sName, int& nType) const ;
bool GetNextTool( int nFamily, std::string& sName, int& nType) const ;
bool SetCurrTool( const std::string& sName) ;
bool SaveCurrTool( void) ;
bool IsCurrToolModified( void) const ;
bool SetCurrToolParam( int nType, bool bVal) ;
bool SetCurrToolParam( int nType, int nVal) ;
bool SetCurrToolParam( int nType, double dVal) ;
bool SetCurrToolParam( int nType, const std::string& sVal) ;
template <class T> bool SetCurrToolValInNotes( int nType, const std::string& sKey, T& Val) ;
bool RemoveCurrToolValInNotes( int nType, const std::string& sKey) ;
bool GetCurrToolParam( int nType, bool& bVal) const ;
bool GetCurrToolParam( int nType, int& nVal) const ;
bool GetCurrToolParam( int nType, double& dVal) const ;
bool GetCurrToolParam( int nType, std::string& sVal) const ;
template <class T> bool GetCurrToolValInNotes( int nType, const std::string& sKey, T& Val) const ;
bool GetCurrToolMaxDepth( double dSafe, double& dMaxDepth) const ;
bool GetCurrToolThDiam( double& dThDiam) const ;
const ToolData* GetCurrTool(void) const
{ return (m_bCurrTool ? &m_tdCurrTool : nullptr) ; }
private :
bool Clear( void) ;
bool LoadHeader( Scanner& TheScanner, int& nVersion, int& nToolSize, int& nTotal, bool& bEnd) ;
bool LoadOneTool( Scanner& TheScanner, int nToolSize, bool& bEnd) ;
bool SaveHeader( Writer& TheWriter) const ;
bool SaveOneTool( const EgtUUID& Uuid, int& nCounter, Writer& TheWriter) const ;
bool VerifyTool( int nFamily, std::string& sName, int& nType) const ;
bool UpdateCurrToolHolderData( void) ;
private :
typedef std::unordered_map< EgtUUID, ToolData> UUIDTDATA_UMAP ;
typedef std::map< std::string, EgtUUID> STRUUID_MAP ;
typedef STRUUID_MAP::const_iterator STRUUID_CITER ;
private :
std::string m_sToolsDir ;
std::string m_sToolsPath ;
UUIDTDATA_UMAP m_utData ;
STRUUID_MAP m_suData ;
mutable STRUUID_CITER m_suCIter ;
bool m_bCurrTool ;
ToolData m_tdCurrTool ;
mutable bool m_bModified ;
mutable UUIDVECTOR m_utModified ;
} ;
//----------------------------------------------------------------------------
template <class T>
bool
ToolsMgr::SetCurrToolValInNotes( int nType, const std::string& sKey, T& Val)
{
// deve esistere utensile corrente
if ( ! m_bCurrTool)
return false ;
// le note ammesse sono utente o sistema
if ( nType != TPA_USERNOTES && nType != TPA_SYSNOTES)
return false ;
// recupero le note da aggiornare
std::string sNotes ;
if ( ! m_tdCurrTool.GetParam( nType, sNotes))
return false ;
// aggiorno le note
if ( ! SetValInNotes( sKey, Val, sNotes))
return false ;
// salvo le note
return m_tdCurrTool.SetParam( nType, sNotes) ;
}
//----------------------------------------------------------------------------
template <class T>
bool
ToolsMgr::GetCurrToolValInNotes( int nType, const std::string& sKey, T& Val) const
{
// deve esistere utensile corrente
if ( ! m_bCurrTool)
return false ;
// le note ammesse sono utente o sistema
if ( nType != TPA_USERNOTES && nType != TPA_SYSNOTES)
return false ;
// recupero le note da cui leggere il valore
std::string sNotes ;
if ( ! m_tdCurrTool.GetParam( nType, sNotes))
return false ;
// recupero il valore
return GetValInNotes( sNotes, sKey, Val) ;
}
//----------------------------------------------------------------------------
inline bool
ToolsMgr::RemoveCurrToolValInNotes( int nType, const std::string& sKey)
{
// deve esistere utensile corrente
if ( ! m_bCurrTool)
return false ;
// le note ammesse sono utente o sistema
if ( nType != TPA_USERNOTES && nType != TPA_SYSNOTES)
return false ;
// recupero le note da aggiornare
std::string sNotes ;
if ( ! m_tdCurrTool.GetParam( nType, sNotes))
return false ;
// aggiorno le note
if ( ! RemoveValInNotes( sKey, sNotes))
return false ;
// salvo le note
return m_tdCurrTool.SetParam( nType, sNotes) ;
}