Files
EgtMachKernel/MachMgrOperations.cpp
T
Dario Sassi e2a7280a07 EgtMachKernel 1.6h3 :
- piccoli adattamenti
- Count invece di Num o Nbr.
2015-08-18 07:32:29 +00:00

356 lines
12 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : MachMgrMachinings.cpp Data : 21.05.15 Versione : 1.6e7
// Contenuto : Implementazione gestione lavorazioni 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 "Drilling.h"
#include "Sawing.h"
#include "Milling.h"
#include "/EgtDev/Include/EGkGdbIterator.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EGnFileUtils.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
using namespace std ;
//----------------------------------------------------------------------------
int
MachMgr::GetOperationCount( void) const
{
// recupero il gruppo delle operazioni nella macchinata corrente
int nOperGrpId = GetCurrOperId() ;
if ( nOperGrpId == GDB_ID_NULL)
return 0 ;
// ritorno numero di operazioni
return m_pGeomDB->GetGroupObjs( nOperGrpId) ;
}
//----------------------------------------------------------------------------
int
MachMgr::GetFirstOperation( void) const
{
// recupero il gruppo delle operazioni nella macchinata corrente
int nOperGrpId = GetCurrOperId() ;
if ( nOperGrpId == GDB_ID_NULL)
return GDB_ID_NULL ;
// recupero il primo sottogruppo
int nId = m_pGeomDB->GetFirstGroupInGroup( nOperGrpId) ;
return nId ;
}
//----------------------------------------------------------------------------
int
MachMgr::GetNextOperation( int nId) const
{
// recupero il gruppo delle operazioni nella macchinata corrente
int nOperGrpId = GetCurrOperId() ;
if ( nOperGrpId == GDB_ID_NULL)
return GDB_ID_NULL ;
// verifico che il gruppo ricevuto sia corretto
if ( m_pGeomDB->GetParentId( nId) != nOperGrpId)
return GDB_ID_NULL ;
// recupero il successivo sottogruppo
int nNextId = m_pGeomDB->GetNextGroup( nId) ;
return nNextId ;
}
//----------------------------------------------------------------------------
bool
MachMgr::GetOperationNewName( string& sName) const
{
// il parametro nome deve essere valido
if ( &sName == nullptr)
return false ;
// il gruppo per le operazioni deve essere presente nella macchinata corrente
if ( GetCurrOperId() == GDB_ID_NULL)
return false ;
// se nome vuoto, assegno radice standard
if ( sName.empty())
sName = "Oper" ;
// verifico che il nome sia unico
int nCount = 1 ;
string sOrigName = sName ;
while ( GetOperationId( sName) != GDB_ID_NULL) {
++ nCount ;
sName = sOrigName + "_" + ToString( nCount) ;
}
return true ;
}
//----------------------------------------------------------------------------
std::string
MachMgr::GetOperationName( int nId) const
{
// recupero il gruppo delle operazioni nella macchinata corrente
int nOperGrpId = GetCurrOperId() ;
if ( nOperGrpId == GDB_ID_NULL)
return "" ;
// verifico che il gruppo ricevuto sia corretto
if ( m_pGeomDB->GetParentId( nId) != nOperGrpId)
return "" ;
// recupero il nome del gruppo riferito
string sName ;
m_pGeomDB->GetName( nId, sName) ;
return sName ;
}
//----------------------------------------------------------------------------
int
MachMgr::GetOperationId( const string& sName) const
{
// verifica dei parametri
if ( &sName == nullptr || sName.empty())
return false ;
// recupero il gruppo delle operazioni nella macchinata corrente
int nOperGrpId = GetCurrOperId() ;
if ( nOperGrpId == GDB_ID_NULL)
return GDB_ID_NULL ;
// 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 sOperGrpName ;
if ( pIter->GetName( sOperGrpName) && EqualNoCase( sOperGrpName, sName))
return pIter->GetId() ;
// passo al successivo
bIter = pIter->GoToNextGroup() ;
}
return GDB_ID_NULL ;
}
//----------------------------------------------------------------------------
// Dispositions
//----------------------------------------------------------------------------
int
MachMgr::AddDisposition( const string& sName)
{
// recupero il gruppo delle operazioni nella macchinata corrente
int nOperGrpId = GetCurrOperId() ;
if ( nOperGrpId == GDB_ID_NULL)
return GDB_ID_NULL ;
// recupero nome originale, partendo da quello proposto
string sNewName = sName ;
if ( ! GetOperationNewName( sNewName))
return GDB_ID_NULL ;
// inserisco il gruppo
int nId = m_pGeomDB->AddGroup( GDB_ID_NULL, nOperGrpId, GLOB_FRM) ;
if ( nId == GDB_ID_NULL)
return GDB_ID_NULL ;
// assegno il nome
m_pGeomDB->SetName( nId, sNewName) ;
// installo il gestore della disposizione
Disposition* pDisp = new(nothrow) Disposition ;
if ( pDisp == nullptr)
return GDB_ID_NULL ;
m_pGeomDB->SetUserObj( nId, pDisp) ;
pDisp->Init( this) ;
return nId ;
}
//----------------------------------------------------------------------------
// Machinings
//----------------------------------------------------------------------------
bool
MachMgr::SetCurrMachining( int nId)
{
// recupero il gruppo delle operazioni nella macchinata corrente
int nOperGrpId = GetCurrOperId() ;
if ( nOperGrpId == GDB_ID_NULL)
return false ;
// verifico che il gruppo di indice nId appartenga a questo gruppo
if ( m_pGeomDB->GetParentId( nId) != nOperGrpId)
return false ;
// verifico che questo gruppo sia realmente una lavorazione
Machining* pMch = dynamic_cast<Machining*>( m_pGeomDB->GetUserObj( nId)) ;
if ( pMch == nullptr)
return false ;
// gli imposto il manager generale delle lavorazioni
pMch->Init( this) ;
// imposto la lavorazione corrente
m_nCurrMachiningId = nId ;
return true ;
}
//----------------------------------------------------------------------------
bool
MachMgr::ResetCurrMachining( void)
{
m_nCurrMachiningId = GDB_ID_NULL ;
return true ;
}
//----------------------------------------------------------------------------
int
MachMgr::GetCurrMachining( void) const
{
// recupero il gruppo delle operazioni nella macchinata corrente
int nOperGrpId = GetCurrOperId() ;
if ( nOperGrpId == GDB_ID_NULL)
return GDB_ID_NULL ;
// verifico che la lavorazione corrente appartenga a questo gruppo
if ( m_pGeomDB->GetParentId( m_nCurrMachiningId) == nOperGrpId)
return m_nCurrMachiningId ;
else
return GDB_ID_NULL ;
}
//----------------------------------------------------------------------------
int
MachMgr::AddMachining( const string& sName, const std::string& sMachining)
{
// recupero il gestore delle lavorazioni della macchina corrente
MachiningsMgr* pMMgr = GetCurrMachiningsMgr() ;
if ( pMMgr == nullptr)
return GDB_ID_NULL ;
// recupero il tipo di lavorazione
const MachiningData* pMd = pMMgr->GetMachining( sMachining) ;
if ( pMd == nullptr)
return GDB_ID_NULL ;
int nMchType = pMd->GetType() ;
// recupero il gruppo delle operazioni nella macchinata corrente
int nOperGrpId = GetCurrOperId() ;
if ( nOperGrpId == GDB_ID_NULL)
return GDB_ID_NULL ;
// recupero nome originale, partendo da quello proposto
string sNewName = sName ;
if ( ! GetOperationNewName( sNewName))
return GDB_ID_NULL ;
// inserisco il gruppo
int nId = m_pGeomDB->AddGroup( GDB_ID_NULL, nOperGrpId, GLOB_FRM) ;
if ( nId == GDB_ID_NULL)
return GDB_ID_NULL ;
// assegno il nome
m_pGeomDB->SetName( nId, sNewName) ;
// installo il gestore della lavorazione
Machining* pMch = nullptr ;
switch ( nMchType) {
case MT_DRILLING : pMch = new( nothrow) Drilling ; break ;
case MT_SAWING : pMch = new( nothrow) Sawing ; break ;
case MT_MILLING : pMch = new( nothrow) Milling ; break ;
}
if ( pMch == nullptr) {
m_pGeomDB->Erase( nId) ;
return GDB_ID_NULL ;
}
m_pGeomDB->SetUserObj( nId, pMch) ;
pMch->Init( this) ;
if ( ! pMch->Prepare( sMachining)) {
m_pGeomDB->Erase( nId) ;
return GDB_ID_NULL ;
}
// la dichiaro lavorazione corrente
m_nCurrMachiningId = nId ;
return nId ;
}
//----------------------------------------------------------------------------
bool
MachMgr::SetMachiningParam( int nType, bool bVal)
{
// recupero la lavorazione corrente
int nCurrMchId = GetCurrMachining() ;
if ( nCurrMchId == GDB_ID_NULL)
return false ;
// ne recupero il gestore
Machining* pMch = dynamic_cast<Machining*>( m_pGeomDB->GetUserObj( nCurrMchId)) ;
if ( pMch == nullptr)
return false ;
// imposto il parametro
return pMch->SetParam( nType, bVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::SetMachiningParam( int nType, int nVal)
{
// recupero la lavorazione corrente
int nCurrMchId = GetCurrMachining() ;
if ( nCurrMchId == GDB_ID_NULL)
return false ;
// ne recupero il gestore
Machining* pMch = dynamic_cast<Machining*>( m_pGeomDB->GetUserObj( nCurrMchId)) ;
if ( pMch == nullptr)
return false ;
// imposto il parametro
return pMch->SetParam( nType, nVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::SetMachiningParam( int nType, double dVal)
{
// recupero la lavorazione corrente
int nCurrMchId = GetCurrMachining() ;
if ( nCurrMchId == GDB_ID_NULL)
return false ;
// ne recupero il gestore
Machining* pMch = dynamic_cast<Machining*>( m_pGeomDB->GetUserObj( nCurrMchId)) ;
if ( pMch == nullptr)
return false ;
// imposto il parametro
return pMch->SetParam( nType, dVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::SetMachiningParam( int nType, const string& sVal)
{
// recupero la lavorazione corrente
int nCurrMchId = GetCurrMachining() ;
if ( nCurrMchId == GDB_ID_NULL)
return false ;
// ne recupero il gestore
Machining* pMch = dynamic_cast<Machining*>( m_pGeomDB->GetUserObj( nCurrMchId)) ;
if ( pMch == nullptr)
return false ;
// imposto il parametro
return pMch->SetParam( nType, sVal) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::SetMachiningGeometry( const SELVECTOR& vIds)
{
// recupero la lavorazione corrente
int nCurrMchId = GetCurrMachining() ;
if ( nCurrMchId == GDB_ID_NULL)
return false ;
// ne recupero il gestore
Machining* pMch = dynamic_cast<Machining*>( m_pGeomDB->GetUserObj( nCurrMchId)) ;
if ( pMch == nullptr)
return false ;
// imposto la geometria
return pMch->SetGeometry( vIds) ;
}
//----------------------------------------------------------------------------
bool
MachMgr::Apply( void)
{
// recupero la lavorazione corrente
int nCurrMchId = GetCurrMachining() ;
if ( nCurrMchId == GDB_ID_NULL)
return false ;
// ne recupero il gestore
Machining* pMch = dynamic_cast<Machining*>( m_pGeomDB->GetUserObj( nCurrMchId)) ;
if ( pMch == nullptr)
return false ;
// imposto la geometria
return pMch->Apply() ;
}