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
+59 -8
View File
@@ -258,13 +258,28 @@ Disposition::SetTable( const string& sTable)
//----------------------------------------------------------------------------
bool
Disposition::GetTableRef1( Point3d& ptRef1)
Disposition::GetTable( string& sTable) const
{
// verifico MachMgr e GeomDB
if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr)
return false ;
// verifico tavola
if ( ! m_bTabOk && ! SetTable( m_sTabName))
if ( ! m_bTabOk && ! const_cast<Disposition*>(this)->SetTable( m_sTabName))
return false ;
// recupero il nome della tavola
sTable = m_sTabName ;
return true ;
}
//----------------------------------------------------------------------------
bool
Disposition::GetTableRef1( Point3d& ptRef1) const
{
// verifico MachMgr e GeomDB
if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr)
return false ;
// verifico tavola
if ( ! m_bTabOk && ! const_cast<Disposition*>(this)->SetTable( m_sTabName))
return false ;
// recupero il primo riferimento della tavola
ptRef1 = m_ptRef1 ;
@@ -282,9 +297,9 @@ Disposition::Apply(void)
for ( auto& FixData : m_vFixData) {
// se sottopezzo da caricare
if ( FixData.nId == GDB_ID_NULL) {
int nId = AddSubPiece( FixData.sName, FixData.ptPos, false) ;
int nId = AddFixture( FixData.sName, FixData.ptPos, FixData.dAng, false) ;
if ( nId == GDB_ID_NULL) {
string sOut = "Error adding subpiece " + FixData.sName ;
string sOut = "Error adding fixture " + FixData.sName ;
LOG_ERROR( GetEMkLogger(), sOut.c_str()) ;
}
else
@@ -320,7 +335,7 @@ Disposition::Apply(void)
//----------------------------------------------------------------------------
int
Disposition::AddSubPiece( const string& sName, const Point3d& ptPos, double dAngDeg, bool bAddToList)
Disposition::AddFixture( const string& sName, const Point3d& ptPos, double dAngDeg, bool bAddToList)
{
// verifico MachMgr e GeomDB
if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr)
@@ -358,7 +373,7 @@ Disposition::AddSubPiece( const string& sName, const Point3d& ptPos, double dAng
//----------------------------------------------------------------------------
bool
Disposition::MoveSubPiece( int nId, const Vector3d& vtMove)
Disposition::MoveFixture( int nId, const Vector3d& vtMove)
{
// verifica validità sottopezzo
if ( ! VerifyFixture( nId))
@@ -380,7 +395,7 @@ Disposition::MoveSubPiece( int nId, const Vector3d& vtMove)
//----------------------------------------------------------------------------
bool
Disposition::RotateSubPiece( int nId, double dAngDeg)
Disposition::RotateFixture( int nId, double dAngDeg)
{
// verifica validità sottopezzo
if ( ! VerifyFixture( nId))
@@ -402,7 +417,7 @@ Disposition::RotateSubPiece( int nId, double dAngDeg)
//----------------------------------------------------------------------------
bool
Disposition::RemoveSubPiece( int nId)
Disposition::RemoveFixture( int nId)
{
// verifica validità sottopezzo
if ( ! VerifyFixture( nId))
@@ -645,3 +660,39 @@ Disposition::VerifyRawPart( int nRawId) const
return false ;
return true ;
}
//----------------------------------------------------------------------------
bool
Disposition::GetFixtureData( int nInd, string& sName, int& nId, Point3d& ptPos, double& dAngDeg) const
{
// verifico MachMgr e GeomDB
if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr)
return false ;
// verifico l'indice
if ( nInd < 0 || nInd >= int( m_vFixData.size()))
return false ;
// recupero i dati
sName = m_vFixData[nInd].sName ;
nId = m_vFixData[nInd].nId ;
ptPos = m_vFixData[nInd].ptPos ;
dAngDeg = m_vFixData[nInd].dAng ;
return true ;
}
//----------------------------------------------------------------------------
bool
Disposition::GetMoveRawData( int nInd, int& nRawId, int& nType, Point3d& ptPos, int& nFlag) const
{
// verifico MachMgr e GeomDB
if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr)
return false ;
// verifico l'indice
if ( nInd < 0 || nInd >= int( m_vMvrData.size()))
return false ;
// recupero i dati
nRawId = m_vMvrData[nInd].nRawId ;
nType = m_vMvrData[nInd].nType ;
ptPos = m_vMvrData[nInd].ptP ;
nFlag = m_vMvrData[nInd].nFlag ;
return true ;
}
+9 -6
View File
@@ -38,7 +38,7 @@ struct MoveRawData
int nRawId ; // identificativo del grezzo
int nType ; // tipo di movimento ( 1=MoveToCorner, 2=MoveToCenter, 3=Rotate)
Point3d ptP ; // punto di riferimento / angoli di Eulero CAC'
int nFlag ; // flag tipo movimento/rotazione
int nFlag ; // flag sottotipo movimento/rotazione
enum { NONE = 0, COR = 1, CEN = 2, ROT = 3} ;
MoveRawData( void)
: nRawId( 0), nType( NONE), ptP(), nFlag( 0) {}
@@ -66,17 +66,20 @@ class Disposition : public IUserObj
bool Init( MachMgr* pMchMgr) ;
bool SetTable( const std::string& sTable) ;
bool Apply( void) ;
bool GetTableRef1( Point3d& ptRef1) ;
int AddSubPiece( const std::string& sName, const Point3d& ptPos, double dAngDeg = 0, bool bAddToList = true) ;
bool MoveSubPiece( int nId, const Vector3d& vtMove) ;
bool RotateSubPiece( int nId, double dAngDeg) ;
bool RemoveSubPiece( int nId) ;
bool GetTable( std::string& sTable) const ;
bool GetTableRef1( Point3d& ptRef1) const ;
int AddFixture( const std::string& sName, const Point3d& ptPos, double dAngDeg = 0, bool bAddToList = true) ;
bool MoveFixture( int nId, const Vector3d& vtMove) ;
bool RotateFixture( int nId, double dAngDeg) ;
bool RemoveFixture( int nId) ;
bool MoveToCornerRawPart( int nRawId, const Point3d& ptP, int nFlag, bool bAddToList = true) ;
bool MoveToCenterRawPart( int nRawId, const Point3d& ptP, int nFlag, bool bAddToList = true) ;
bool MoveRawPart( int nRawId, const Vector3d& vtMove) ;
bool RotateRawPart( int nRawId, const Vector3d& vtAx, double dAngRotDeg) ;
bool ApplyRotationToRawPart( int nRawId, double dAngCDeg, double dAngADeg, double dAngC1Deg) ;
bool RemoveRawPart( int nRawId) ;
bool GetFixtureData( int nInd, std::string& sName, int& nId, Point3d& ptPos, double& dAngDeg) const ;
bool GetMoveRawData( int nInd, int& nRawId, int& nType, Point3d& ptPos, int& nFlag) const ;
private :
bool VerifyFixture( int nFixtId) const ;
BIN
View File
Binary file not shown.
+4
View File
@@ -220,16 +220,19 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
<ClCompile Include="DrillingData.cpp" />
<ClCompile Include="EMkDllMain.cpp" />
<ClCompile Include="Exit.cpp" />
<ClCompile Include="Generator.cpp" />
<ClCompile Include="GeoCalc.cpp" />
<ClCompile Include="Machine.cpp" />
<ClCompile Include="MachineAxes.cpp" />
<ClCompile Include="MachineCalc.cpp" />
<ClCompile Include="MachineLua.cpp" />
<ClCompile Include="MachineHeads.cpp" />
<ClCompile Include="MachineWriter.cpp" />
<ClCompile Include="Machining.cpp" />
<ClCompile Include="MachiningsMgr.cpp" />
<ClCompile Include="MachMgrBasic.cpp" />
<ClCompile Include="MachMgrFixtures.cpp" />
<ClCompile Include="MachMgrGeneration.cpp" />
<ClCompile Include="MachMgrMachGroups.cpp" />
<ClCompile Include="MachMgrMachines.cpp" />
<ClCompile Include="MachMgrOperations.cpp" />
@@ -266,6 +269,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
<ClInclude Include="Drilling.h" />
<ClInclude Include="DrillingData.h" />
<ClInclude Include="Exit.h" />
<ClInclude Include="Generator.h" />
<ClInclude Include="GeoCalc.h" />
<ClInclude Include="MachConst.h" />
<ClInclude Include="Machine.h" />
+15
View File
@@ -37,6 +37,9 @@
<Filter Include="Source Files\Simulation">
<UniqueIdentifier>{fbbebf38-66cd-4db8-863b-bc1a1cbf95d9}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Generation">
<UniqueIdentifier>{f3ac3061-c243-4c9a-a852-4c9d92f5842d}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="EMkDllMain.cpp">
@@ -141,6 +144,15 @@
<ClCompile Include="MachMgrSimulation.cpp">
<Filter>Source Files\MachMgr</Filter>
</ClCompile>
<ClCompile Include="Generator.cpp">
<Filter>Source Files\Generation</Filter>
</ClCompile>
<ClCompile Include="MachMgrGeneration.cpp">
<Filter>Source Files\MachMgr</Filter>
</ClCompile>
<ClCompile Include="MachineWriter.cpp">
<Filter>Source Files\Machine</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="DllMain.h">
@@ -242,6 +254,9 @@
<ClInclude Include="Simulator.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Generator.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="EgtMachKernel.rc">
+296
View File
@@ -0,0 +1,296 @@
//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : Generator.cpp Data : 28.10.15 Versione : 1.6j4
// Contenuto : Implementazione della classe generator.
//
//
//
// Modifiche : 28.10.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "DllMain.h"
#include "Generator.h"
#include "MachMgr.h"
#include "Disposition.h"
#include "Machining.h"
#include "MachiningConst.h"
#include "/EgtDev/Include/EMkToolConst.h"
#include "/EgtDev/Include/EMkOperationConst.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
using namespace std ;
//----------------------------------------------------------------------------
Generator::Generator( void)
{
m_pMchMgr = nullptr ;
m_pGeomDB = nullptr ;
m_pMachine = nullptr ;
m_sPrevTool.clear() ;
m_sTool.clear() ;
m_AxesName.reserve( 8) ;
m_AxesVal.reserve( 8) ;
}
//----------------------------------------------------------------------------
Generator::~Generator( void)
{
}
//----------------------------------------------------------------------------
bool
Generator::Init( MachMgr* pMchMgr)
{
// verifico ambiente
if ( pMchMgr == nullptr || pMchMgr->GetContextId() == 0 ||
pMchMgr->GetGeomDB() == nullptr || pMchMgr->GetCurrMachine() == nullptr)
return false ;
m_pMchMgr = pMchMgr ;
m_pGeomDB = m_pMchMgr->GetGeomDB() ;
m_pMachine = m_pMchMgr->GetCurrMachine() ;
m_sTool.clear() ;
return true ;
}
//----------------------------------------------------------------------------
bool
Generator::Run( const string& sCncFile)
{
// verifico ci sia una macchinata corrente
if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr || m_pMachine == nullptr ||
m_pMchMgr->GetCurrMachGroup() == GDB_ID_NULL)
return false ;
// predispongo per la scrittura del file
if ( ! m_pMachine->WriterOpen( sCncFile)) {
LOG_INFO( GetEMkLogger(), "Error opening Cnc file") ;
return false ;
}
// emetto inizio programma
m_pMachine->WriterEmit( "(Start Program)") ;
// ciclo su tutte le operazioni della macchinata
bool bOk = true ;
int nInd = 0 ;
int nOpId = m_pMchMgr->GetFirstOperation() ;
while ( bOk && nOpId != GDB_ID_NULL) {
// incremento l'indice della operazione
++ nInd ;
// la prima operazione deve essere una disposizione
if ( nInd == 1) {
if ( m_pMchMgr->GetOperationType( nOpId) != OPER_DISP) {
bOk = false ;
continue ;
}
}
// processo l'operazione
switch ( m_pMchMgr->GetOperationType( nOpId)) {
case OPER_DISP :
if ( ! ProcessDisposition( nOpId, nInd))
bOk = false ;
break ;
case OPER_DRILLING :
case OPER_SAWING :
case OPER_MILLING :
if ( ! ProcessMachining( nOpId, nInd))
bOk = false ;
break ;
default :
break ;
}
// passo alla operazione successiva
nOpId = m_pMchMgr->GetNextOperation( nOpId) ;
}
// emetto fine programma
m_pMachine->WriterEmit( "(End Program)") ;
// chiudo il file
m_pMachine->WriterClose() ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
Generator::ProcessDisposition( int nOpId, int nOpInd)
{
// parametri della disposizione
Disposition* pDisp = dynamic_cast<Disposition*>( m_pGeomDB->GetUserObj( nOpId)) ;
if ( pDisp == nullptr)
return false ;
// emetto i dati
string sOut ;
sOut = "(" + ToString( nOpInd) + ": Disposition)" ;
m_pMachine->WriterEmit( sOut) ;
string sTable ;
pDisp->GetTable( sTable) ;
Point3d ptRef1 ;
pDisp->GetTableRef1( ptRef1) ;
sOut = "(Table=" + sTable + " R1=" + ToString( ptRef1) + ")" ;
m_pMachine->WriterEmit( sOut) ;
// bloccaggi
for ( int i = 0 ; ; ++ i) {
string sName ;
int nId ;
Point3d ptPos ;
double dAngDeg ;
if ( pDisp->GetFixtureData( i, sName, nId, ptPos, dAngDeg)) {
sOut = "(Fixture " + sName + " " + ToString( nId) + " (" + ToString( ptPos) + ") " + ToString( dAngDeg) + ")" ;
m_pMachine->WriterEmit( sOut) ;
}
else
break ;
}
// movimento grezzi
for ( int i = 0 ; ; ++ i) {
int nRawId ;
int nType ;
Point3d ptPos ;
int nFlag ;
if ( pDisp->GetMoveRawData( i, nRawId, nType, ptPos, nFlag)) {
sOut = "(MoveRaw " + ToString( nRawId) + " " + ToString( nType) + " (" + ToString( ptPos) + ") " + ToString( nFlag) + ")" ;
m_pMachine->WriterEmit( sOut) ;
}
else
break ;
}
m_pMachine->WriterEmit( "(End Disposition)") ;
return true ;
}
//----------------------------------------------------------------------------
bool
Generator::ProcessMachining( int nOpId, int nOpInd)
{
// parametri della lavorazione
Machining* pMch = dynamic_cast<Machining*>( m_pGeomDB->GetUserObj( nOpId)) ;
if ( pMch == nullptr)
return false ;
// emetto inizio lavorazione
{ string sOut ;
string sName ;
m_pGeomDB->GetName( nOpId, sName) ;
sOut = "(" + ToString( nOpInd) + ": Machining=" + sName + ")" ;
m_pMachine->WriterEmit( sOut) ; }
// aggiorno utensile e assi macchina
if ( ! UpdateTool( nOpId) || ! UpdateAxes())
return false ;
// parametri dell'utensile
const ToolData& Tdata = pMch->GetToolData() ;
// Emetto dati utensile
{ string sOut ;
sOut = "(Tool " + m_sTool + ( m_sTool != m_sPrevTool ? " changed" : "") + " S=" + ToString(Tdata.m_dSpeed) + ")" ;
m_pMachine->WriterEmit( sOut) ; }
// ciclo su tutti i percorsi CL della lavorazione
bool bOk = true ;
int nClPathInd = 0 ;
int nClId = m_pGeomDB->GetFirstNameInGroup( nOpId, MCH_CL) ;
int nClPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ;
while ( bOk && nClPathId != GDB_ID_NULL) {
++ nClPathInd ;
// processo il percorso di lavoro
if ( ! ProcessClPath( nClPathId, nClPathInd, nOpId, nOpInd))
bOk = false ;
// passo al percorso successivo
nClPathId = m_pGeomDB->GetNextGroup( nClPathId) ;
}
// emetto fine lavorazione
m_pMachine->WriterEmit( "(End Machining)") ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
Generator::ProcessClPath( int nClPathId, int nClPathInd, int nOpId, int nOpInd)
{
string sOut = "(ClPath " + ToString( nClPathInd) + ")" ;
m_pMachine->WriterEmit( sOut) ;
// ciclo su tutte le entità del percorsi CL
bool bOk = true ;
int nEntInd = 0 ;
int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ;
while ( bOk && nEntId != GDB_ID_NULL) {
++ nEntInd ;
// processo l'entità
if ( ! ProcessClEnt( nEntId, nEntInd, nClPathId, nClPathInd, nOpId, nOpInd))
bOk = false ;
// passo all'entità successivo
nEntId = m_pGeomDB->GetNext( nEntId) ;
}
m_pMachine->WriterEmit( "(End ClPath)") ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
Generator::ProcessClEnt( int nEntId, int nEntInd, int nClPathId, int nClPathInd, int nOpId, int nOpInd)
{
// Recupero i dati Cam
CamData* pCamData = dynamic_cast<CamData*>( m_pGeomDB->GetUserObj( nEntId)) ;
if ( pCamData == nullptr || pCamData->GetAxesStatus() != CamData::AS_OK)
return false ;
const DBLVECTOR& AxesEnd = pCamData->GetAxisVal() ;
// Verifico se movimento in rapido
bool bRapid = ( pCamData->GetFeed() < EPS_SMALL) ;
// Emetto movimento
string sOut ;
sOut += ( bRapid ? "G0 " : "G1 ") ;
for ( size_t i = 0 ; i < m_AxesName.size() ; ++ i) {
sOut += m_AxesName[i] + ToString( AxesEnd[i], 3) + " " ;
}
if ( ! bRapid)
sOut += "F" + ToString( pCamData->GetFeed()) ;
m_pMachine->WriterEmit( sOut) ;
return true ;
}
//----------------------------------------------------------------------------
bool
Generator::UpdateTool( int nOpId)
{
// Salvo l'utensile attuale come precedente
m_sPrevTool = m_sTool ;
// Recupero l'utensile della lavorazione corrente
string sTool ;
Machining* pMch = dynamic_cast<Machining*>( m_pGeomDB->GetUserObj( nOpId)) ;
if ( pMch == nullptr || ! pMch->GetParam( MPA_TOOL, sTool))
return false ;
if ( ! m_pMchMgr->TdbSetCurrTool( sTool))
return false ;
// se cambiato, attivo l'utensile della lavorazione
if ( sTool != m_sTool) {
string sHead ; m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ;
int nExit ; m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ;
if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit))
return false ;
m_sTool = sTool ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
Generator::UpdateAxes( void)
{
// Carico i nomi degli assi macchina attivi
return m_pMachine->GetAllCurrAxesName( m_AxesName) ;
}
+47
View File
@@ -0,0 +1,47 @@
//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : Generator.h Data : 28.10.15 Versione : 1.6j4
// Contenuto : Dichiarazione della classe Generator.
//
//
//
// Modifiche : 28.10.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include "CamData.h"
class MachMgr ;
class IGeomDB ;
class Machine ;
//----------------------------------------------------------------------------
class Generator
{
public :
Generator( void) ;
~Generator( void) ;
bool Init( MachMgr* pMchMgr) ;
bool Run( const std::string& sCncFile) ;
private :
bool ProcessDisposition( int nOpId, int nOpInd) ;
bool ProcessMachining( int nOpId, int nOpInd) ;
bool ProcessClPath( int nClPathId, int nClPathInd, int nOpId, int nOpInd) ;
bool ProcessClEnt( int nEntId, int nEntInd, int nClPathId, int nClPathInd, int nOpId, int nOpInd) ;
bool UpdateTool( int nOpId) ;
bool UpdateAxes( void) ;
private :
MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni
IGeomDB* m_pGeomDB ; // puntatore al DB geometrico
Machine* m_pMachine ; // puntatore alla macchina
std::string m_sPrevTool ; // nome dell'utensile precedente
std::string m_sTool ; // nome dell'utensile corrente
STRVECTOR m_AxesName ; // nomi degli assi macchina attivi
DBLVECTOR m_AxesVal ; // valori degli assi macchina all'inizio del movimento corrente
} ;
+32 -27
View File
@@ -96,37 +96,26 @@ class MachMgr : public IMachMgr
virtual bool SetTable( const std::string& sTable) ;
virtual bool GetTableRef1( Point3d& ptPos) ;
virtual bool GetTableArea1( int& nAreaId) ;
virtual int AddSubPiece( const std::string& sName, const Point3d& ptPos, double dAngRotDeg) ;
virtual int AddFixture( const std::string& sName, const Point3d& ptPos, double dAngRotDeg) ;
virtual bool ShowOnlyTable( bool bVal) ;
// Machine Calc
virtual bool SetAxisPos( const std::string& sAxis, double dVal) ;
virtual bool GetAxisPos( const std::string& sAxis, double& dVal) ;
virtual bool GetAxisHomePos( const std::string& sAxis, double& dHomeVal) ;
virtual bool ResetAxisPos( const std::string& sAxis) ;
virtual bool ResetAllAxesPos( void) ;
virtual bool LoadTool( const std::string& sHead, int nExit, const std::string& sTool) ;
virtual bool ResetHeadSet( const std::string& sHead) ;
virtual bool SetCalcTable( const std::string& sTable) ;
virtual bool SetCalcTool( const std::string& sTool, const std::string& sHead, int nExit) ;
virtual bool GetCalcTool( std::string& sTool) ;
virtual bool GetCalcAngles( const Vector3d& vtDirT, const Vector3d& vtDirA,
int& nStat, double& dAngA1, double& dAngB1, double& dAngA2, double& dAngB2) ;
virtual bool GetCalcPositions( const Point3d& ptP, double dAngA, double dAngB,
int& nStat, double& dX, double& dY, double& dZ) ;
virtual bool VerifyOutOfStroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) ;
// Tool DataBase
// Tools DataBase
virtual bool TdbGetToolNewName( std::string& sName) ;
virtual bool TdbAddTool( const std::string& sName, int nType) ;
virtual bool TdbCopyTool( const std::string& sSource, const std::string& sName) ;
virtual bool TdbRemoveTool( const std::string& sName) ;
virtual bool TdbGetFirstTool( int nFamily, std::string& sName, int& nType) ;
virtual bool TdbGetNextTool( int nFamily, std::string& sName, int& nType) ;
virtual bool TdbSetToolParam( const std::string& sName, int nType, int nVal) ;
virtual bool TdbSetToolParam( const std::string& sName, int nType, double dVal) ;
virtual bool TdbSetToolParam( const std::string& sName, int nType, const std::string& sVal) ;
virtual bool TdbGetToolParam( const std::string& sName, int nType, int& nVal) const ;
virtual bool TdbGetToolParam( const std::string& sName, int nType, double& dVal) const ;
virtual bool TdbGetToolParam( const std::string& sName, int nType, std::string& sVal) const ;
virtual bool TdbSetCurrTool( const std::string& sName) ;
virtual bool TdbSaveCurrTool( void) ;
virtual bool TdbSetCurrToolParam( int nType, int nVal) ;
virtual bool TdbSetCurrToolParam( int nType, double dVal) ;
virtual bool TdbSetCurrToolParam( int nType, const std::string& sVal) ;
virtual bool TdbGetCurrToolParam( int nType, int& nVal) const ;
virtual bool TdbGetCurrToolParam( int nType, double& dVal) const ;
virtual bool TdbGetCurrToolParam( int nType, std::string& sVal) const ;
virtual bool TdbSave( void) const ;
// Machinings DataBase
// ...
// Operations : general
virtual int GetOperationCount( void) const ;
virtual int GetFirstOperation( void) const ;
@@ -156,6 +145,25 @@ class MachMgr : public IMachMgr
virtual bool SimMove( void) ;
virtual bool SimSetStep( double dStep) ;
virtual bool SimStop( void) ;
// Generation
virtual bool Generate( const std::string& sCncFile) ;
// Machine Calc
virtual bool SetCalcTable( const std::string& sTable) ;
virtual bool SetCalcTool( const std::string& sTool, const std::string& sHead, int nExit) ;
virtual bool GetCalcTool( std::string& sTool) ;
virtual bool GetCalcAngles( const Vector3d& vtDirT, const Vector3d& vtDirA,
int& nStat, double& dAngA1, double& dAngB1, double& dAngA2, double& dAngB2) ;
virtual bool GetCalcPositions( const Point3d& ptP, double dAngA, double dAngB,
int& nStat, double& dX, double& dY, double& dZ) ;
virtual bool VerifyOutOfStroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) ;
// Machine Move
virtual bool SetAxisPos( const std::string& sAxis, double dVal) ;
virtual bool GetAxisPos( const std::string& sAxis, double& dVal) ;
virtual bool GetAxisHomePos( const std::string& sAxis, double& dHomeVal) ;
virtual bool ResetAxisPos( const std::string& sAxis) ;
virtual bool ResetAllAxesPos( void) ;
virtual bool LoadTool( const std::string& sHead, int nExit, const std::string& sTool) ;
virtual bool ResetHeadSet( const std::string& sHead) ;
public :
MachMgr( void) ;
@@ -197,9 +205,6 @@ class MachMgr : public IMachMgr
bool GetAllCurrAxesName( STRVECTOR& vAxName) ;
bool GetAllCalcAxesHomePos( DBLVECTOR& vAxHomeVal) ;
double GetCalcRot1W( void) ;
// Tool DataBase
ToolData* TdbGetToolData( const std::string& sName) ;
const ToolData* TdbGetToolData( const std::string& sName) const ;
// operations
bool GetOperationNewName( std::string& sName) const ;
+2 -2
View File
@@ -69,7 +69,7 @@ MachMgr::GetTableArea1( int& nAreaId)
//----------------------------------------------------------------------------
int
MachMgr::AddSubPiece( const string& sName, const Point3d& ptPos, double dAngRotDeg)
MachMgr::AddFixture( const string& sName, const Point3d& ptPos, double dAngRotDeg)
{
// recupero la prima operazione, deve essere la disposizione
int nDispId = GetFirstOperation() ;
@@ -78,7 +78,7 @@ MachMgr::AddSubPiece( const string& sName, const Point3d& ptPos, double dAngRotD
if ( pDisp == nullptr)
return false ;
// eseguo l'operazione
return pDisp->AddSubPiece( sName, ptPos, dAngRotDeg) ;
return pDisp->AddFixture( sName, ptPos, dAngRotDeg) ;
}
//----------------------------------------------------------------------------
+40
View File
@@ -0,0 +1,40 @@
//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : MachMgrGeneration.cpp Data : 28.10.15 Versione : 1.6j4
// Contenuto : Implementazione gestione generazione della classe MachMgr.
//
//
//
// Modifiche : 28.10.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "DllMain.h"
#include "MachMgr.h"
#include "MachConst.h"
#include "Generator.h"
using namespace std ;
//----------------------------------------------------------------------------
bool
MachMgr::Generate( const string& sCncFile)
{
// inizializzazione generatore
Generator genPP ;
if ( ! genPP.Init( this)) {
LOG_ERROR( GetEMkLogger(), "Error on Generate Init")
return false ;
}
// esecuzione della generazione
if ( ! genPP.Run( sCncFile)) {
LOG_ERROR( GetEMkLogger(), "Error on Generate Run")
return false ;
}
return true ;
}
+1 -1
View File
@@ -45,7 +45,7 @@ MachMgr::LoadMachine( const string& sMachineName)
// creo e carico il DB utensili
PtrOwner<ToolsMgr> pTsMgr( new( nothrow) ToolsMgr) ;
string sToolsFile = m_sMachinesDir + "\\" + sMachineName + "\\" + TOOLS_DIR + "\\" + TOOLS_FILE ;
if ( IsNull( pTsMgr) || ! pTsMgr->Init( sToolsFile) || ! pTsMgr->Load())
if ( IsNull( pTsMgr) || ! pTsMgr->Load( sToolsFile))
return false ;
// creo e carico il DB lavorazioni
PtrOwner<MachiningsMgr> pMsMgr( new( nothrow) MachiningsMgr) ;
+94 -82
View File
@@ -18,6 +18,18 @@
using namespace std ;
//----------------------------------------------------------------------------
bool
MachMgr::TdbGetToolNewName( string& sName)
{
// recupero il gestore di utensili della macchina corrente
ToolsMgr* pTsMgr = GetCurrToolsMgr() ;
if ( pTsMgr == nullptr)
return false ;
// verifico nome ed eventualmente lo modifico per renderlo nuovo
return pTsMgr->GetToolNewName( sName) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::TdbAddTool( const string& sName, int nType)
@@ -80,98 +92,98 @@ MachMgr::TdbGetNextTool( int nFamily, string& sName, int& nType)
//----------------------------------------------------------------------------
bool
MachMgr::TdbSetToolParam( const string& sName, int nType, int nVal)
{
// recupero l'utensile
ToolData* pTdata = TdbGetToolData( sName) ;
if ( pTdata == nullptr)
return false ;
// assegno il parametro
return pTdata->SetParam( nType, nVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::TdbSetToolParam( const string& sName, int nType, double dVal)
{
// recupero l'utensile
ToolData* pTdata = TdbGetToolData( sName) ;
if ( pTdata == nullptr)
return false ;
// assegno il parametro
return pTdata->SetParam( nType, dVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::TdbSetToolParam( const string& sName, int nType, const string& sVal)
{
// recupero l'utensile
ToolData* pTdata = TdbGetToolData( sName) ;
if ( pTdata == nullptr)
return false ;
// assegno il parametro
return pTdata->SetParam( nType, sVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::TdbGetToolParam( const string& sName, int nType, int& nVal) const
{
// recupero l'utensile
const ToolData* pTdata = TdbGetToolData( sName) ;
if ( pTdata == nullptr)
return false ;
// recupero il parametro
return pTdata->GetParam( nType, nVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::TdbGetToolParam( const string& sName, int nType, double& dVal) const
{
// recupero l'utensile
const ToolData* pTdata = TdbGetToolData( sName) ;
if ( pTdata == nullptr)
return false ;
// recupero il parametro
return pTdata->GetParam( nType, dVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::TdbGetToolParam( const string& sName, int nType, string& sVal) const
{
// recupero l'utensile
const ToolData* pTdata = TdbGetToolData( sName) ;
if ( pTdata == nullptr)
return false ;
// recupero il parametro
return pTdata->GetParam( nType, sVal) ;
}
//----------------------------------------------------------------------------
ToolData*
MachMgr::TdbGetToolData( const string& sName)
MachMgr::TdbSetCurrTool( const string& sName)
{
// recupero il gestore di utensili della macchina corrente
ToolsMgr* pTsMgr = GetCurrToolsMgr() ;
if ( pTsMgr == nullptr)
return nullptr ;
// recupero l'utensile
return pTsMgr->GetTool( sName) ;
return false ;
// imposto l'utensile corrente
return pTsMgr->SetCurrTool( sName) ;
}
//----------------------------------------------------------------------------
const ToolData*
MachMgr::TdbGetToolData( const string& sName) const
bool
MachMgr::TdbSaveCurrTool( void)
{
// recupero il gestore di utensili della macchina corrente
ToolsMgr* pTsMgr = GetCurrToolsMgr() ;
if ( pTsMgr == nullptr)
return nullptr ;
// recupero l'utensile
return pTsMgr->GetTool( sName) ;
return false ;
// salvo l'utensile corrente
return pTsMgr->SaveCurrTool() ;
}
//----------------------------------------------------------------------------
bool
MachMgr::TdbSetCurrToolParam( int nType, int nVal)
{
// recupero il gestore di utensili della macchina corrente
ToolsMgr* pTsMgr = GetCurrToolsMgr() ;
if ( pTsMgr == nullptr)
return false ;
// assegno il parametro
return pTsMgr->SetCurrToolParam( nType, nVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::TdbSetCurrToolParam( int nType, double dVal)
{
// recupero il gestore di utensili della macchina corrente
ToolsMgr* pTsMgr = GetCurrToolsMgr() ;
if ( pTsMgr == nullptr)
return false ;
// assegno il parametro
return pTsMgr->SetCurrToolParam( nType, dVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::TdbSetCurrToolParam( int nType, const string& sVal)
{
// recupero il gestore di utensili della macchina corrente
ToolsMgr* pTsMgr = GetCurrToolsMgr() ;
if ( pTsMgr == nullptr)
return false ;
// assegno il parametro
return pTsMgr->SetCurrToolParam( nType, sVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::TdbGetCurrToolParam( int nType, int& nVal) const
{
// recupero il gestore di utensili della macchina corrente
ToolsMgr* pTsMgr = GetCurrToolsMgr() ;
if ( pTsMgr == nullptr)
return false ;
// recupero il parametro
return pTsMgr->GetCurrToolParam( nType, nVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::TdbGetCurrToolParam( int nType, double& dVal) const
{
// recupero il gestore di utensili della macchina corrente
ToolsMgr* pTsMgr = GetCurrToolsMgr() ;
if ( pTsMgr == nullptr)
return false ;
// recupero il parametro
return pTsMgr->GetCurrToolParam( nType, dVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::TdbGetCurrToolParam( int nType, string& sVal) const
{
// recupero il gestore di utensili della macchina corrente
ToolsMgr* pTsMgr = GetCurrToolsMgr() ;
if ( pTsMgr == nullptr)
return false ;
// recupero il parametro
return pTsMgr->GetCurrToolParam( nType, sVal) ;
}
//----------------------------------------------------------------------------
@@ -182,6 +194,6 @@ MachMgr::TdbSave( void) const
ToolsMgr* pTsMgr = GetCurrToolsMgr() ;
if ( pTsMgr == nullptr)
return nullptr ;
// recupero l'utensile
// salvo il db utensili
return pTsMgr->Save() ;
}
+1 -1
View File
@@ -97,7 +97,7 @@ Machine::Init( const string& sMachinesDir, const string& sMachineName, MachMgr*
m_sName = sMachineName ;
// carico la macchina {
string sMachineMde = m_sMachineDir + "\\" + sMachineName + ".Mde" ;
bool bOk = LuaExecFile( sMachineMde) ;
bool bOk = LuaLoadMachine( sMachineMde) ;
// cancello il gruppo temporaneo
m_pGeomDB->Erase( m_nTempGroupId) ;
m_nTempGroupId = GDB_ID_NULL ;
+6 -1
View File
@@ -16,6 +16,7 @@
#include "MachineStruConst.h"
#include "/EgtDev/Include/EGkGeomDB.h"
#include "/EgtDev/Include/EGnLuaMgr.h"
#include "/EgtDev/Include/EGnWriter.h"
#include <unordered_map>
class MachMgr ;
@@ -62,6 +63,9 @@ class Machine
bool GetPositions( const Point3d& ptP, double dA, double dB,
int& nStat, double& dX, double& dY, double& dZ) ;
bool VerifyOutOfStroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) ;
bool WriterOpen( const std::string& sOutFile) ;
bool WriterClose( void) ;
bool WriterEmit( const std::string& sLine) ;
private :
void Clear( void) ;
@@ -100,7 +104,7 @@ class Machine
bool LuaInit( const std::string& sMachineName) ;
bool LuaExit( void) ;
bool LuaExecFile( const std::string& sFile) ;
bool LuaLoadMachine( const std::string& sFile) ;
private :
typedef std::unordered_map< std::string, int> STRINT_UMAP ;
@@ -109,6 +113,7 @@ class Machine
MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni
IGeomDB* m_pGeomDB ; // puntatore al DB geometrico
LuaMgr m_LuaMgr ; // interprete lua della macchina
Writer m_Writer ; // scrittore di file di testo
std::string m_sName ; // nome della macchina
std::string m_sMachineDir ; // direttorio della macchina
int m_nGroupId ; // Id del gruppo della macchina
+1 -1
View File
@@ -96,7 +96,7 @@ Machine::SetCurrTool( const string& sTool, const string& sHead, int nExit)
if ( nToolId == GDB_ID_NULL || m_pGeomDB->GetGdbType( nToolId) != GDB_TY_GROUP)
return false ;
double dTLen = 0 ;
if ( ! m_pMchMgr->TdbGetToolParam( sTool, TPA_LEN, dTLen))
if ( ! m_pMchMgr->TdbSetCurrTool( sTool) || ! m_pMchMgr->TdbGetCurrToolParam( TPA_LEN, dTLen))
return false ;
// assegno tutti i dati
m_nCalcHeadId = nHeadId ;
+1 -1
View File
@@ -44,7 +44,7 @@ Machine::LoadTool( const string& sHead, int nExit, const string& sTool)
return EnableHeadInSet( sHead) ;
// verifico esistenza file utensile
string sDraw ;
if ( ! m_pMchMgr->TdbGetToolParam( sTool, TPA_DRAW, sDraw))
if ( ! m_pMchMgr->TdbSetCurrTool( sTool) || ! m_pMchMgr->TdbGetCurrToolParam( TPA_DRAW, sDraw))
return false ;
string sToolFile = m_sMachineDir + "\\" + TOOLS_DIR + "\\" + sDraw ;
if ( ! ExistsFile( sToolFile))
+3 -3
View File
@@ -48,7 +48,7 @@ Machine::LuaInit( const string& sMachineName)
m_LuaMgr.SetLuaLibsDir( m_pMchMgr->GetLuaLibsDir()) ;
// carico la libreria standard
m_LuaMgr.Require( m_pMchMgr->GetLuaLastRequire()) ;
// registro le funzioni per lua
// registro le funzioni di lettura macchina per lua
m_LuaMgr.RegisterFunction( "EmtGeneral", Machine::LuaEmtGeneral) ;
m_LuaMgr.RegisterFunction( "EmtBase", Machine::LuaEmtBase) ;
m_LuaMgr.RegisterFunction( "EmtTable", Machine::LuaEmtTable) ;
@@ -72,10 +72,10 @@ Machine::LuaExit( void)
//----------------------------------------------------------------------------
bool
Machine::LuaExecFile( const string& sFile)
Machine::LuaLoadMachine( const string& sFile)
{
// info
string sOut = "LuaExecFile : " + sFile ;
string sOut = "LuaLoadMachine : " + sFile ;
LOG_INFO( GetEMkLogger(), sOut.c_str())
// imposto contesto corretto
int nOldCtx = ExeGetCurrentContext() ;
+41
View File
@@ -0,0 +1,41 @@
//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : MachineLua.cpp Data : 29.10.15 Versione : 1.6j4
// Contenuto : Implementazione gestione macchina : funzioni output.
//
//
//
// Modifiche : 29.10.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "MachMgr.h"
#include "DllMain.h"
using namespace std ;
//----------------------------------------------------------------------------
bool
Machine::WriterOpen( const string& sOutFile)
{
m_Writer.Close() ;
return m_Writer.Init( sOutFile) ;
}
//----------------------------------------------------------------------------
bool
Machine::WriterClose( void)
{
return m_Writer.Close() ;
}
//----------------------------------------------------------------------------
bool
Machine::WriterEmit( const string& sLine)
{
return m_Writer.OutText( sLine) ;
}
+7 -5
View File
@@ -1,8 +1,8 @@
//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : Simulation.cpp Data : 19.10.15 Versione : 1.6j2
// Contenuto : Implementazione della classe Simulation.
// File : Simulator.cpp Data : 19.10.15 Versione : 1.6j2
// Contenuto : Implementazione della classe Simulator.
//
//
//
@@ -17,6 +17,7 @@
#include "MachMgr.h"
#include "Machining.h"
#include "MachiningConst.h"
#include "/EgtDev/Include/EMkToolConst.h"
#include "/EgtDev/Include/EMkOperationConst.h"
using namespace std ;
@@ -186,12 +187,13 @@ Simulator::UpdateTool( void)
Machining* pMch = dynamic_cast<Machining*>( m_pGeomDB->GetUserObj( m_nOpId)) ;
if ( pMch == nullptr || ! pMch->GetParam( MPA_TOOL, sTool))
return false ;
const ToolData* pTdata = m_pMchMgr->TdbGetToolData( sTool) ;
if ( pTdata == nullptr)
if ( ! m_pMchMgr->TdbSetCurrTool( sTool))
return false ;
// se cambiato, attivo l'utensile della lavorazione
if ( sTool != m_sTool) {
if ( ! m_pMchMgr->SetCalcTool( sTool, pTdata->m_sHead, pTdata->m_nExit))
string sHead ; m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ;
int nExit ; m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ;
if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit))
return false ;
m_sTool = sTool ;
}
+2
View File
@@ -251,6 +251,8 @@ ToolData::SetParam( int nType, int nVal)
m_nExit = nVal ;
return true ;
case TPA_TYPE :
if ( ! IsValidToolType( nVal))
return false ;
m_nType = nVal ;
return true ;
}
+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) ;
}
+16 -7
View File
@@ -25,25 +25,32 @@ class ToolsMgr
{
public :
ToolsMgr( void) ;
bool Init( const std::string& sToolsFile) ;
bool Load( void) ;
bool Load( const std::string& sToolsFile) ;
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) ;
ToolData* GetTool( const EgtUUID& Uuid) ;
ToolData* GetTool( 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 SetCurrToolParam( int nType, int nVal) ;
bool SetCurrToolParam( int nType, double dVal) ;
bool SetCurrToolParam( int nType, const std::string& sVal) ;
bool GetCurrToolParam( int nType, int& nVal) const ;
bool GetCurrToolParam( int nType, double& dVal) const ;
bool GetCurrToolParam( int nType, std::string& sVal) const ;
private :
bool Clear( void) ;
bool LoadHeader( Scanner& TheScanner, int& nTotal, bool& bEnd) ;
bool LoadOneTool( Scanner& TheScanner, bool& bEnd) ;
bool SaveHeader( Writer& TheWriter) const ;
bool SaveOneTool( const EgtUUID& Uuid, Writer& TheWriter) const ;
bool VerifyCurrTool( int nFamily, std::string& sName, int& nType) const ;
bool SaveOneTool( const EgtUUID& Uuid, int& nCounter, Writer& TheWriter) const ;
bool VerifyTool( int nFamily, std::string& sName, int& nType) const ;
private :
typedef std::unordered_map< EgtUUID, ToolData> UUIDTDATA_UMAP ;
@@ -55,5 +62,7 @@ class ToolsMgr
UUIDTDATA_UMAP m_utData ;
STRUUID_MAP m_suData ;
mutable STRUUID_CITER m_suCIter ;
mutable int m_nCounter ;
bool m_bCurrTool ;
ToolData m_tdCurrTool ;
mutable bool m_bModified ;
} ;