Files
EgtMachKernel/MachMgrPhases.cpp
T
Dario Sassi a8c34397be EgtMachKernel 1.6n3 :
- prima versione della gestione delle fasi di lavorazione.
2016-02-11 10:20:54 +00:00

198 lines
6.8 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2016-2016
//----------------------------------------------------------------------------
// File : MachMgrPhases.cpp Data : 09.02.16 Versione : 1.6n3
// Contenuto : Implementazione gestione fasi della classe MachMgr.
//
//
//
// Modifiche : 09.02.16 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "DllMain.h"
#include "MachMgr.h"
#include "Disposition.h"
#include "Machining.h"
#include "MachConst.h"
#include "/EgtDev/Include/EGkGdbIterator.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
using namespace std ;
//----------------------------------------------------------------------------
int
MachMgr::AddPhase( void)
{
// recupero la tavola della fase precedente
string sTable ;
int nDispId = GetFirstOperation() ;
while ( nDispId != GDB_ID_NULL) {
const Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( nDispId)) ;
if ( pDisp != nullptr)
pDisp->GetTable( sTable) ;
nDispId = GetNextOperation( nDispId) ;
}
// incremento il numero totale delle fasi
++ m_nPhasesCount ;
// imposto la nuova fase corrente
PrepareCurrPhase( m_nPhasesCount, false) ;
// inserisco la prima operazione di fase, sempre una disposizione
string sName = "Disp" + ToString( m_nCurrPhase, 2) ;
m_nCurrDispId = AddDisposition( sName) ;
if ( m_nCurrDispId == GDB_ID_NULL)
return 0 ;
// assegno la tavola della disposizione precedente
if ( ! sTable.empty()) {
Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ;
pDisp->SetTable( sTable) ;
}
return m_nCurrPhase ;
}
//----------------------------------------------------------------------------
bool
MachMgr::SetCurrPhase( int nPhase)
{
return PrepareCurrPhase( nPhase, true) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::PrepareCurrPhase( int nPhase, bool bDoDisp)
{
// verifico esistenza fase
if ( nPhase <= 0 || nPhase > m_nPhasesCount)
return false ;
// se coincide con la vecchia fase, non devo fare alcunché
if ( nPhase == m_nCurrPhase)
return true ;
// se c'è lavorazione corrente e non appartiene a questa fase, reset
const Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( GetCurrMachining())) ;
if ( pMch != nullptr && pMch->GetPhase() != nPhase)
ResetCurrMachining() ;
// tolgo i pezzi dai grezzi che non appartengono alla fase
int nRawId = GetFirstRawPart() ;
while ( nRawId != GDB_ID_NULL) {
// recupero le fasi in cui è presente il grezzo (se manca è fase 1)
INTVECTOR vPhase ;
if ( ! m_pGeomDB->GetInfo( nRawId, MACH_RAW_PHASE, vPhase) || vPhase.empty())
vPhase.emplace_back( 1) ;
// se non appartiene
if ( find( vPhase.begin(), vPhase.end(), nPhase) == vPhase.end())
SwapRawPartParts( nRawId, false) ;
// passo al prossimo
nRawId = GetNextRawPart( nRawId) ;
}
// inserisco i pezzi nei grezzi che appartengono alla fase
nRawId = GetFirstRawPart() ;
while ( nRawId != GDB_ID_NULL) {
// recupero le fasi in cui è presente il grezzo (se manca è fase 1)
INTVECTOR vPhase ;
if ( ! m_pGeomDB->GetInfo( nRawId, MACH_RAW_PHASE, vPhase) || vPhase.empty())
vPhase.emplace_back( 1) ;
// se appartiene
if ( find( vPhase.begin(), vPhase.end(), nPhase) != vPhase.end())
SwapRawPartParts( nRawId, true) ;
// passo al prossimo
nRawId = GetNextRawPart( nRawId) ;
}
// aggiorno stato grezzi
nRawId = GetFirstRawPart() ;
while ( nRawId != GDB_ID_NULL) {
// recupero le fasi in cui è presente il grezzo
INTVECTOR vPhase ;
if ( ! m_pGeomDB->GetInfo( nRawId, MACH_RAW_PHASE, vPhase) || vPhase.empty())
vPhase.emplace_back( 1) ;
// verifico
bool bOn = ( find( vPhase.begin(), vPhase.end(), nPhase) != vPhase.end()) ;
m_pGeomDB->SetStatus( nRawId, ( bOn ? GDB_ST_ON : GDB_ST_OFF)) ;
// passo al prossimo
nRawId = GetNextRawPart( nRawId) ;
}
// imposto disposizione corrente
int nDispId = GDB_ID_NULL ;
if ( bDoDisp) {
Disposition* pDisp = nullptr ;
nDispId = GetFirstOperation() ;
while ( nDispId != GDB_ID_NULL) {
pDisp = GetDisposition( m_pGeomDB->GetUserObj( nDispId)) ;
if ( pDisp != nullptr && pDisp->GetPhase() == nPhase)
break ;
else
pDisp = nullptr ;
nDispId = GetNextOperation( nDispId) ;
}
if ( pDisp != nullptr) {
pDisp->Init( this) ;
if ( pDisp->IsSetTableName() && ! pDisp->Apply())
return false ;
}
else
return false ;
}
// aggiorno stato lavorazioni
int nMchId = GetFirstOperation() ;
while ( nMchId != GDB_ID_NULL) {
const Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nMchId)) ;
if ( pMch != nullptr) {
m_pGeomDB->SetStatus( nMchId, ( pMch->GetPhase() == nPhase ? GDB_ST_ON : GDB_ST_OFF)) ;
}
nMchId = GetNextOperation( nMchId) ;
}
// assegno l'indice della nuova fase corrente
m_nCurrPhase = nPhase ;
m_nCurrDispId = nDispId ;
return true ;
}
//----------------------------------------------------------------------------
int
MachMgr::GetCurrPhase( void) const
{
return m_nCurrPhase ;
}
//----------------------------------------------------------------------------
bool
MachMgr::RemoveLastPhase( void)
{
// non è possibile rimuovere la prima e unica fase
if ( m_nPhasesCount <= 1)
return false ;
// imposto le relative lavorazioni come disattivate e senza fase
// elimino i grezzi appartenenti a questa sola fase e la relativa disposizione
// se era corrente, rendo corrente la precedente
if ( m_nCurrPhase == m_nPhasesCount)
SetCurrPhase( m_nCurrPhase - 1) ;
-- m_nPhasesCount ;
return true ;
}
//----------------------------------------------------------------------------
int
MachMgr::GetPhaseCount( void) const
{
return m_nPhasesCount ;
}
//----------------------------------------------------------------------------
int
MachMgr::CalcPhaseCount( void) const
{
// ciclo sulle disposizioni
int nPhases = 0 ;
int nDispId = GetFirstOperation() ;
while ( nDispId != GDB_ID_NULL) {
Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( nDispId)) ;
if ( pDisp != nullptr)
nPhases = max( nPhases, pDisp->GetPhase()) ;
nDispId = GetNextOperation( nDispId) ;
}
return nPhases ;
}