d66cc47936
- aggiunta funzione ChangeMachGroupName di MachMgr.
484 lines
17 KiB
C++
484 lines
17 KiB
C++
//----------------------------------------------------------------------------
|
|
// 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 "Disposition.h"
|
|
#include "/EgtDev/Include/EGkGdbIterator.h"
|
|
#include "/EgtDev/Include/EGnStringKeyVal.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
MachMgr::GetMachGroupCount( 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 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
MachMgr::GetLastMachGroup( void) const
|
|
{
|
|
// verifica del gruppo base per le lavorazioni
|
|
if ( ! VerifyMachBase())
|
|
return GDB_ID_NULL ;
|
|
// recupero l'ultimo sottogruppo
|
|
int nId = m_pGeomDB->GetLastGroupInGroup( m_nMachBaseId) ;
|
|
return nId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
MachMgr::GetPrevMachGroup( 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 precedente sottogruppo
|
|
int nNextId = m_pGeomDB->GetPrevGroup( 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 = "Mach_1" ;
|
|
return true ;
|
|
}
|
|
// se nome vuoto, assegno radice standard
|
|
if ( sName.empty())
|
|
sName = "Mach_1" ;
|
|
// se presenti caratteri vietati, li sostituisco
|
|
ValidateVal( sName) ;
|
|
// verifico che il nome sia unico
|
|
int nCount = 1 ;
|
|
string sOrigName = sName ;
|
|
if ( sOrigName.length() > 2 && sOrigName.rfind( "_1") == sOrigName.length() - 2)
|
|
sOrigName.erase( sOrigName.length() - 2) ;
|
|
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 == nullptr || sName.empty() || GetMachGroupId( sName) != GDB_ID_NULL)
|
|
return GDB_ID_NULL ;
|
|
// se nome macchina vuoto, verifico esista una macchina corrente
|
|
string sMachName ;
|
|
if ( &sMachineName == nullptr || sMachineName.empty()) {
|
|
if ( ! GetCurrMachineName( sMachName))
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// altrimenti, verifica ed eventuale caricamento della macchina
|
|
else {
|
|
if ( ! LoadMachine( sMachineName))
|
|
return GDB_ID_NULL ;
|
|
sMachName = sMachineName ;
|
|
}
|
|
// 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, sMachName) ;
|
|
// 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 fissaggi
|
|
int nFixtId = m_pGeomDB->AddGroup( GDB_ID_NULL, nNewId, GLOB_FRM) ;
|
|
m_pGeomDB->SetName( nFixtId, MACH_FIXT_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) ;
|
|
// predispongo e verifico impostazioni e aggiungo prima fase
|
|
if ( ! PrepareCurrMachGroup( nNewId) || AddPhase() == 0) {
|
|
m_pGeomDB->Erase( nNewId) ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// reset tavola e utensile correnti
|
|
Machine* pMch = GetCurrMachine() ;
|
|
if ( pMch != nullptr) {
|
|
pMch->ResetCurrTable() ;
|
|
pMch->ResetCurrTool() ;
|
|
}
|
|
// aggiorno attrezzaggio attivo
|
|
UpdateCurrSetup() ;
|
|
// nascondo i pezzi rimasti sotto la radice
|
|
ShowRootParts( false) ;
|
|
// rendo visibile il nuovo gruppo corrente e la relativa macchina
|
|
m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_ON) ;
|
|
m_pGeomDB->SetStatus( GetCurrMachineId(), GDB_ST_ON) ;
|
|
// restituisco l'identificativo del gruppo
|
|
return nNewId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
MachMgr::CopyMachGroup( const string& sSouName, const string& sName)
|
|
{
|
|
// recupero il gruppo sorgente
|
|
int nSouMGrpId = GetMachGroupId( sSouName) ;
|
|
if ( nSouMGrpId == GDB_ID_NULL)
|
|
return GDB_ID_NULL ;
|
|
// verifico esista la sua macchina
|
|
string sMachineName ;
|
|
m_pGeomDB->GetInfo( nSouMGrpId, MACH_MACHINE_KEY, sMachineName) ;
|
|
if ( sMachineName.empty() || ! LoadMachine( sMachineName))
|
|
return GDB_ID_NULL ;
|
|
// verifico nome nuovo gruppo (non deve essere vuoto e non deve esserci già un gruppo con questo nome)
|
|
if ( &sName == nullptr || sName.empty() || GetMachGroupId( sName) != GDB_ID_NULL)
|
|
return GDB_ID_NULL ;
|
|
// reset gruppo corrente
|
|
ResetCurrMachGroup() ;
|
|
// eseguo la copia del gruppo sorgente e la metto in coda
|
|
int nNewMGrpId = m_pGeomDB->Copy( nSouMGrpId, GDB_ID_NULL, m_nMachBaseId) ;
|
|
if ( nNewMGrpId == GDB_ID_NULL)
|
|
return GDB_ID_NULL ;
|
|
// assegno il nome
|
|
m_pGeomDB->SetName( nNewMGrpId, sName) ;
|
|
// converto opportunamente gli indicativi dei grezzi nelle disposizioni
|
|
int nSouRawPartId = m_pGeomDB->GetFirstGroupInGroup( m_pGeomDB->GetFirstNameInGroup( nSouMGrpId, MACH_RAW_GROUP)) ;
|
|
int nNewRawPartId = m_pGeomDB->GetFirstGroupInGroup( m_pGeomDB->GetFirstNameInGroup( nNewMGrpId, MACH_RAW_GROUP)) ;
|
|
while ( nSouRawPartId != GDB_ID_NULL && nNewRawPartId != GDB_ID_NULL) {
|
|
// ciclo sulle disposizioni del nuovo gruppo di lavoro
|
|
int nOperId = m_pGeomDB->GetFirstGroupInGroup( m_pGeomDB->GetFirstNameInGroup( nNewMGrpId, MACH_OPER_GROUP)) ;
|
|
while ( nOperId != GDB_ID_NULL) {
|
|
Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( nOperId)) ;
|
|
if ( pDisp != nullptr)
|
|
pDisp->UpdateRawPartId( nSouRawPartId, nNewRawPartId) ;
|
|
nOperId = m_pGeomDB->GetNextGroup( nOperId) ;
|
|
}
|
|
// passo alla coppia successiva
|
|
nSouRawPartId = m_pGeomDB->GetNextGroup( nSouRawPartId) ;
|
|
nNewRawPartId = m_pGeomDB->GetNextGroup( nNewRawPartId) ;
|
|
}
|
|
// lo rendo corrente
|
|
SetCurrMachGroup( nNewMGrpId) ;
|
|
// restituisco l'identificativo del gruppo
|
|
return nNewMGrpId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
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 ;
|
|
// verifica della macchina
|
|
bool bMName = m_pGeomDB->GetInfo( nId, MACH_MACHINE_KEY, mgData.MGeoName) ;
|
|
// scansiono i sottogruppi
|
|
bool bSetup = false ;
|
|
bool bFixt = false ;
|
|
bool bRaw = false ;
|
|
bool bOper = false ;
|
|
int nGrpId = m_pGeomDB->GetFirstGroupInGroup( nId) ;
|
|
while ( nGrpId != GDB_ID_NULL) {
|
|
string sName ;
|
|
if ( m_pGeomDB->GetName( nGrpId, sName)) {
|
|
if ( sName == MACH_SETUP_GROUP) {
|
|
if ( ! bSetup)
|
|
mgData.SetupGroupId = nGrpId ;
|
|
bSetup = true ;
|
|
}
|
|
else if ( sName == MACH_FIXT_GROUP) {
|
|
if ( ! bFixt)
|
|
mgData.FixtGroupId = nGrpId ;
|
|
bFixt = true ;
|
|
}
|
|
else if ( sName == MACH_RAW_GROUP) {
|
|
if ( ! bRaw)
|
|
mgData.RawGroupId = nGrpId ;
|
|
bRaw = true ;
|
|
}
|
|
else if ( sName == MACH_OPER_GROUP) {
|
|
if ( ! bOper)
|
|
mgData.OperGroupId = nGrpId ;
|
|
bOper = true ;
|
|
}
|
|
}
|
|
// passo al successivo
|
|
nGrpId = m_pGeomDB->GetNextGroup( nGrpId) ;
|
|
}
|
|
return ( bMName && bSetup && bRaw && bOper) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::ChangeMachGroupName( int nId, const string& sNewName)
|
|
{
|
|
// verifica del gruppo base per le lavorazioni
|
|
if ( ! VerifyMachBase())
|
|
return false ;
|
|
// verifico che il gruppo ricevuto sia corretto
|
|
if ( m_pGeomDB->GetParentId( nId) != m_nMachBaseId)
|
|
return false ;
|
|
// verifico nome non vuoto e non esista già un gruppo con lo stesso nome
|
|
if ( &sNewName == nullptr || sNewName.empty() || GetMachGroupId( sNewName) != GDB_ID_NULL)
|
|
return false ;
|
|
// cambio il nome del gruppo di lavoro
|
|
if ( ! m_pGeomDB->SetName( nId, sNewName))
|
|
return false ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
string
|
|
MachMgr::GetMachGroupName( int nId) const
|
|
{
|
|
// verifica del gruppo base per le lavorazioni
|
|
if ( ! VerifyMachBase())
|
|
return "" ;
|
|
// verifico che il gruppo ricevuto sia corretto
|
|
if ( m_pGeomDB->GetParentId( nId) != m_nMachBaseId)
|
|
return "" ;
|
|
// recupero il nome del gruppo riferito
|
|
string sName ;
|
|
m_pGeomDB->GetName( nId, sName) ;
|
|
return sName ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
string
|
|
MachMgr::GetMachGroupMachineName( int nId) const
|
|
{
|
|
// verifica del gruppo base per le lavorazioni
|
|
if ( ! VerifyMachBase())
|
|
return "" ;
|
|
// verifico che il gruppo ricevuto sia corretto
|
|
if ( m_pGeomDB->GetParentId( nId) != m_nMachBaseId)
|
|
return "" ;
|
|
// recupero il nome della macchina del gruppo riferito
|
|
string sName ;
|
|
m_pGeomDB->GetInfo( nId, MACH_MACHINE_KEY, sName) ;
|
|
return sName ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
MachMgr::GetMachGroupId( const string& sName) const
|
|
{
|
|
// verifica dei parametri
|
|
if ( &sName == nullptr || sName.empty())
|
|
return GDB_ID_NULL ;
|
|
// verifica del gruppo base per le lavorazioni
|
|
if ( ! VerifyMachBase())
|
|
return GDB_ID_NULL ;
|
|
// recupero l'identificativo del gruppo con il nome indicato
|
|
int nGrpId = m_pGeomDB->GetFirstGroupInGroup( m_nMachBaseId) ;
|
|
while ( nGrpId != GDB_ID_NULL) {
|
|
// verifico il nome
|
|
string sMGroupName ;
|
|
if ( m_pGeomDB->GetName( nGrpId, sMGroupName) && EqualNoCase( sMGroupName, sName))
|
|
return nGrpId ;
|
|
// passo al successivo
|
|
nGrpId = m_pGeomDB->GetNextGroup( nGrpId) ;
|
|
}
|
|
return GDB_ID_NULL ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::SetCurrMachGroup( int nId)
|
|
{
|
|
// predispongo e verifico impostazioni
|
|
if ( ! PrepareCurrMachGroup( nId))
|
|
return false ;
|
|
// aggiorno attrezzaggio attivo
|
|
UpdateCurrSetup() ;
|
|
// imposto la prima fase come corrente
|
|
if ( ! SetCurrPhase( 1))
|
|
return false ;
|
|
// nascondo i pezzi rimasti sotto la radice
|
|
ShowRootParts( false) ;
|
|
// rendo visibile il nuovo gruppo corrente e la relativa macchina
|
|
m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_ON) ;
|
|
m_pGeomDB->SetStatus( GetCurrMachineId(), GDB_ST_ON) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
MachMgr::PrepareCurrMachGroup( 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 ;
|
|
}
|
|
// verifica ed eventuale caricamento della macchina
|
|
if ( ! LoadMachine( mgData.MGeoName))
|
|
return false ;
|
|
// se esiste gruppo corrente, lo disabilito
|
|
if ( m_nCurrMGrpId != GDB_ID_NULL) {
|
|
// termino eventuale simulazione attiva
|
|
SimExit() ;
|
|
// riporto i pezzi nei grezzi precedenti nella loro posizione standard
|
|
SwapParts( false) ;
|
|
// nascondo precedente gruppo corrente e la relativa macchina
|
|
m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_OFF) ;
|
|
m_pGeomDB->SetStatus( GetCurrMachineId(),GDB_ST_OFF) ;
|
|
}
|
|
// imposto i dati del nuovo gruppo corrente
|
|
m_nCurrMGrpId = nId ;
|
|
m_cCurrMGrp = mgData ;
|
|
m_nCurrMch = GetMachine( m_cCurrMGrp.MGeoName) ;
|
|
if ( ! m_stuMgr.Init( this)) {
|
|
m_nCurrMGrpId = GDB_ID_NULL ;
|
|
return false ;
|
|
}
|
|
m_stuMgr.Load() ;
|
|
m_nPhasesCount = CalcPhaseCount() ;
|
|
m_nCurrPhase = 0 ;
|
|
m_nCurrDispId = GDB_ID_NULL ;
|
|
m_nCurrMachiningId = GDB_ID_NULL ;
|
|
if ( m_pSimul != nullptr) {
|
|
delete m_pSimul ;
|
|
m_pSimul = nullptr ;
|
|
}
|
|
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 ;
|
|
// termino eventuale simulazione attiva
|
|
SimExit() ;
|
|
// riporto i pezzi nei grezzi nella loro posizione standard
|
|
SwapParts( false) ;
|
|
// visualizzo pezzi rimasti sotto la radice
|
|
ShowRootParts( true) ;
|
|
// nascondo gruppo corrente e la relativa macchina
|
|
m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_OFF) ;
|
|
m_pGeomDB->SetStatus( GetCurrMachineId(), GDB_ST_OFF) ;
|
|
// dichiaro nessun gruppo e lavorazione correnti, lascio corrente la macchina
|
|
m_nCurrMGrpId = GDB_ID_NULL ;
|
|
m_nCurrMachiningId = 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 ;
|
|
}
|