EgtMachKernel 1.6d3 :
- refactoring e correzioni.
This commit is contained in:
@@ -0,0 +1,307 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2015-2015
|
||||
//----------------------------------------------------------------------------
|
||||
// File : MachMgrMachGroups.cpp Data : 16.04.15 Versione : 1.6d3
|
||||
// Contenuto : Implementazione gestione gruppi di lavoro della classe MachMgr.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 16.04.15 DS Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "DllMain.h"
|
||||
#include "MachMgr.h"
|
||||
#include "MachConst.h"
|
||||
#include "/EgtDev/Include/EGkGdbIterator.h"
|
||||
#include "/EgtDev/Include/EGnStringUtils.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
|
||||
using namespace std ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
MachMgr::GetMachGroupNbr( void) const
|
||||
{
|
||||
// verifica del gruppo base per le lavorazioni
|
||||
if ( ! VerifyMachBase())
|
||||
return 0 ;
|
||||
// ritorno numero di gruppi di lavorazione
|
||||
return m_pGeomDB->GetGroupObjs( m_nMachBaseId) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
MachMgr::GetFirstMachGroup( void) const
|
||||
{
|
||||
// verifica del gruppo base per le lavorazioni
|
||||
if ( ! VerifyMachBase())
|
||||
return GDB_ID_NULL ;
|
||||
// recupero il primo sottogruppo
|
||||
int nId = m_pGeomDB->GetFirstGroupInGroup( m_nMachBaseId) ;
|
||||
return nId ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
MachMgr::GetNextMachGroup( int nId) const
|
||||
{
|
||||
// verifica del gruppo base per le lavorazioni
|
||||
if ( ! VerifyMachBase())
|
||||
return GDB_ID_NULL ;
|
||||
// verifico che il gruppo ricevuto sia corretto
|
||||
if ( m_pGeomDB->GetParentId( nId) != m_nMachBaseId)
|
||||
return GDB_ID_NULL ;
|
||||
// recupero il successivo sottogruppo
|
||||
int nNextId = m_pGeomDB->GetNextGroup( nId) ;
|
||||
return nNextId ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
MachMgr::GetMachGroupNewName( string& sName) const
|
||||
{
|
||||
// il parametro nome deve essere valido
|
||||
if ( &sName == nullptr)
|
||||
return false ;
|
||||
// se gruppo base per le lavorazioni assente
|
||||
if ( ! VerifyMachBase()) {
|
||||
if ( sName.empty())
|
||||
sName = "Mach01" ;
|
||||
return true ;
|
||||
}
|
||||
// verifico che il nome sia unico
|
||||
int nCount = 1 ;
|
||||
string sOrigName = sName ;
|
||||
while ( GetMachGroupId( sName) != GDB_ID_NULL) {
|
||||
++ nCount ;
|
||||
sName = sOrigName + "_" + ToString( nCount) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
MachMgr::AddMachGroup( const string& sName, const string& sMachineName)
|
||||
{
|
||||
// verifica ed eventuale creazione del gruppo base per le lavorazioni
|
||||
if ( ! CreateMachBase())
|
||||
return GDB_ID_NULL ;
|
||||
// verifico nome non vuoto e non esista già un gruppo con lo stesso nome
|
||||
if ( sName.empty() || GetMachGroupId( sName) != GDB_ID_NULL)
|
||||
return GDB_ID_NULL ;
|
||||
// verifico esistenza della macchina
|
||||
// !!!! TO DO !!!!
|
||||
// inserisco il gruppo in coda
|
||||
int nNewId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nMachBaseId, GLOB_FRM) ;
|
||||
if ( nNewId == GDB_ID_NULL)
|
||||
return GDB_ID_NULL ;
|
||||
// assegno il nome
|
||||
m_pGeomDB->SetName( nNewId, sName) ;
|
||||
// assegno la macchina
|
||||
m_pGeomDB->SetInfo( nNewId, MACH_MACHINE_KEY, sMachineName) ;
|
||||
// creo il sottogruppo per la macchina
|
||||
int nGeoMachId = m_pGeomDB->AddGroup( GDB_ID_NULL, nNewId, GLOB_FRM) ;
|
||||
m_pGeomDB->SetName( nGeoMachId, MACH_GEOM_GROUP) ;
|
||||
// creo il sottogruppo per l'attrezzaggio
|
||||
int nSetupId = m_pGeomDB->AddGroup( GDB_ID_NULL, nNewId, GLOB_FRM) ;
|
||||
m_pGeomDB->SetName( nSetupId, MACH_SETUP_GROUP) ;
|
||||
// creo il sottogruppo per i grezzi
|
||||
int nRawGroupId = m_pGeomDB->AddGroup( GDB_ID_NULL, nNewId, GLOB_FRM) ;
|
||||
m_pGeomDB->SetName( nRawGroupId, MACH_RAW_GROUP) ;
|
||||
// creo il sottogruppo per le operazioni
|
||||
int nOperGroupId = m_pGeomDB->AddGroup( GDB_ID_NULL, nNewId, GLOB_FRM) ;
|
||||
m_pGeomDB->SetName( nOperGroupId, MACH_OPER_GROUP) ;
|
||||
// rendo corrente il gruppo
|
||||
if ( ! SetCurrMachGroup( nNewId)) {
|
||||
m_pGeomDB->Erase( nNewId) ;
|
||||
return GDB_ID_NULL ;
|
||||
}
|
||||
// restituisco l'identificativo del gruppo
|
||||
return nNewId ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
MachMgr::RemoveMachGroup( int nId)
|
||||
{
|
||||
// verifica del gruppo base per le lavorazioni
|
||||
if ( ! VerifyMachBase())
|
||||
return false ;
|
||||
// verifico sia veramente un gruppo di lavoro
|
||||
if ( m_pGeomDB->GetParentId( nId) != m_nMachBaseId)
|
||||
return false ;
|
||||
// se gruppo corrente, devo definire nuovo corrente
|
||||
if ( m_nCurrMGrpId == nId) {
|
||||
// passo al successivo e se non trovato al precedente
|
||||
int nNextId = m_pGeomDB->GetNextGroup( nId) ;
|
||||
if ( nNextId == GDB_ID_NULL)
|
||||
nNextId = m_pGeomDB->GetPrevGroup( nId) ;
|
||||
// imposto il nuovo corrente (potrebbe essere anche nessuno)
|
||||
if ( nNextId != GDB_ID_NULL)
|
||||
SetCurrMachGroup( nNextId) ;
|
||||
else
|
||||
ResetCurrMachGroup() ;
|
||||
}
|
||||
// eseguo rimozione
|
||||
m_pGeomDB->Erase( nId) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
MachMgr::VerifyMachGroup( int nId, MachGrp& mgData) const
|
||||
{
|
||||
// verifica del parametro
|
||||
if ( &mgData == nullptr)
|
||||
return false ;
|
||||
// verifica collegamento a DB geometrico
|
||||
if ( m_pGeomDB == nullptr)
|
||||
return false ;
|
||||
// scansiono i sottogruppi
|
||||
PtrOwner<IGdbIterator> pIter( CreateGdbIterator( m_pGeomDB)) ;
|
||||
if ( IsNull( pIter))
|
||||
return false ;
|
||||
bool bMGeo = false ;
|
||||
bool bSetup = false ;
|
||||
bool bRaw = false ;
|
||||
bool bOper = false ;
|
||||
bool bIter = pIter->GoToFirstGroupInGroup( nId) ;
|
||||
while ( bIter) {
|
||||
string sName ;
|
||||
if ( pIter->GetName( sName)) {
|
||||
if ( sName == MACH_GEOM_GROUP) {
|
||||
if ( ! bMGeo)
|
||||
mgData.MGeoGroupId = pIter->GetId() ;
|
||||
bMGeo = true ;
|
||||
}
|
||||
else if ( sName == MACH_SETUP_GROUP) {
|
||||
if ( ! bSetup)
|
||||
mgData.SetupGroupId = pIter->GetId() ;
|
||||
bSetup = true ;
|
||||
}
|
||||
else if ( sName == MACH_RAW_GROUP) {
|
||||
if ( ! bRaw)
|
||||
mgData.RawGroupId = pIter->GetId() ;
|
||||
bRaw = true ;
|
||||
}
|
||||
else if ( sName == MACH_OPER_GROUP) {
|
||||
if ( ! bOper)
|
||||
mgData.OperGroupId = pIter->GetId() ;
|
||||
bOper = true ;
|
||||
}
|
||||
}
|
||||
// passo al successivo
|
||||
bIter = pIter->GoToNextGroup() ;
|
||||
}
|
||||
return ( bMGeo && bSetup && bRaw && bOper) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
string
|
||||
MachMgr::GetMachGroupName( int nId) const
|
||||
{
|
||||
// verifica del gruppo base per le lavorazioni
|
||||
if ( ! VerifyMachBase())
|
||||
return "" ;
|
||||
// recupero il nome del gruppo riferito
|
||||
string sName ;
|
||||
m_pGeomDB->GetName( nId, sName) ;
|
||||
return sName ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
MachMgr::GetMachGroupId( const string& sName) const
|
||||
{
|
||||
// verifica dei parametri
|
||||
if ( &sName == nullptr || sName.empty())
|
||||
return false ;
|
||||
// verifica del gruppo base per le lavorazioni
|
||||
if ( ! VerifyMachBase())
|
||||
return false ;
|
||||
// recupero l'identificativo del gruppo con il nome indicato
|
||||
PtrOwner<IGdbIterator> pIter( CreateGdbIterator( m_pGeomDB)) ;
|
||||
if ( IsNull( pIter))
|
||||
return false ;
|
||||
bool bIter = pIter->GoToFirstGroupInGroup( m_nMachBaseId) ;
|
||||
while( bIter) {
|
||||
// verifico il nome
|
||||
string sMGroupName ;
|
||||
if ( pIter->GetName( sMGroupName) && sMGroupName == sName)
|
||||
return pIter->GetId() ;
|
||||
// passo al successivo
|
||||
bIter = pIter->GoToNextGroup() ;
|
||||
}
|
||||
return GDB_ID_NULL ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
MachMgr::SetCurrMachGroup( int nId)
|
||||
{
|
||||
// verifica del gruppo base per le lavorazioni
|
||||
if ( ! VerifyMachBase())
|
||||
return false ;
|
||||
// verifico sia veramente un gruppo di lavoro
|
||||
if ( m_pGeomDB->GetParentId( nId) != m_nMachBaseId)
|
||||
return false ;
|
||||
// recupero i suoi dati
|
||||
MachGrp mgData ;
|
||||
if ( ! VerifyMachGroup( nId, mgData)) {
|
||||
m_nCurrMGrpId = GDB_ID_NULL ;
|
||||
return false ;
|
||||
}
|
||||
// se esiste gruppo corrente, lo disabilito
|
||||
if ( m_nCurrMGrpId != GDB_ID_NULL) {
|
||||
// riporto i pezzi nei grezzi precedenti nella loro posizione standard
|
||||
SwapParts( false) ;
|
||||
// nascondo precedente gruppo corrente
|
||||
m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_OFF) ;
|
||||
}
|
||||
// imposto i dati del nuovo gruppo corrente
|
||||
m_nCurrMGrpId = nId ;
|
||||
m_cCurrMGrp = mgData ;
|
||||
// porto i pezzi dalla loro posizione standard nei grezzi nuovi
|
||||
SwapParts( true) ;
|
||||
// nascondo pezzi rimasti sotto la radice
|
||||
ShowRootParts( false) ;
|
||||
// rendo visibile il nuovo gruppo corrente
|
||||
m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_ON) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
MachMgr::ResetCurrMachGroup( void)
|
||||
{
|
||||
// verifica del gruppo base per le lavorazioni
|
||||
if ( ! VerifyMachBase())
|
||||
return false ;
|
||||
// se non c'è gruppo corrente, posso uscire subito
|
||||
if ( m_nCurrMGrpId == GDB_ID_NULL)
|
||||
return true ;
|
||||
// riporto i pezzi nei grezzi nella loro posizione standard
|
||||
SwapParts( false) ;
|
||||
// visualizzo pezzi rimasti sotto la radice
|
||||
ShowRootParts( true) ;
|
||||
// nascondo gruppo corrente
|
||||
m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_OFF) ;
|
||||
// dichiaro nessun gruppo corrente
|
||||
m_nCurrMGrpId = GDB_ID_NULL ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
MachMgr::GetCurrMachGroup( void) const
|
||||
{
|
||||
// verifica del gruppo base per le lavorazioni
|
||||
if ( ! VerifyMachBase())
|
||||
return GDB_ID_NULL ;
|
||||
// recupero l'indice del gruppo corrente
|
||||
return m_nCurrMGrpId ;
|
||||
}
|
||||
Reference in New Issue
Block a user