2324a8b3f4
- modifiche a DB utensili per gestione utensile corrente - prima versione generatore codice.
297 lines
9.2 KiB
C++
297 lines
9.2 KiB
C++
//----------------------------------------------------------------------------
|
|
// 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) ;
|
|
}
|