//---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- // File : MachMgrOperations.cpp Data : 21.05.15 Versione : 1.6e7 // Contenuto : Implementazione gestione operazioni 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/EMkOperationConst.h" #include "/EgtDev/Include/EGkUserObjFactory.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 ; } //---------------------------------------------------------------------------- int MachMgr::GetLastOperation( void) const { // recupero il gruppo delle operazioni nella macchinata corrente int nOperGrpId = GetCurrOperId() ; if ( nOperGrpId == GDB_ID_NULL) return GDB_ID_NULL ; // recupero l'ultimo sottogruppo int nId = m_pGeomDB->GetLastGroupInGroup( nOperGrpId) ; return nId ; } //---------------------------------------------------------------------------- int MachMgr::GetPrevOperation( 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 precedente sottogruppo int nNextId = m_pGeomDB->GetPrevGroup( nId) ; return nNextId ; } //---------------------------------------------------------------------------- int MachMgr::GetOperationType( int nId) const { // recupero il gruppo delle operazioni nella macchinata corrente int nOperGrpId = GetCurrOperId() ; if ( nOperGrpId == GDB_ID_NULL) return OPER_NULL ; // verifico che il gruppo ricevuto sia corretto if ( m_pGeomDB->GetParentId( nId) != nOperGrpId) return OPER_NULL ; // recupero user object IUserObj* pUserObj = m_pGeomDB->GetUserObj( nId) ; if ( pUserObj == nullptr) return OPER_NULL ; // recupero il tipo di UserObj string sUserObj = pUserObj->GetClassName() ; if ( sUserObj == USEROBJ_GETNAME( Disposition)) return OPER_DISP ; else if ( sUserObj == USEROBJ_GETNAME( Drilling)) return OPER_DRILLING ; else if ( sUserObj == USEROBJ_GETNAME( Sawing)) return OPER_SAWING ; else if ( sUserObj == USEROBJ_GETNAME( Milling)) return OPER_MILLING ; else return OPER_NULL ; } //---------------------------------------------------------------------------- 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 = 0 ; 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 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 ; } //---------------------------------------------------------------------------- bool MachMgr::RemoveOperation( int nId) { // verifico sia una Operazione if ( GetOperationType( nId) == OPER_NULL) return false ; // eseguo la rimozione m_pGeomDB->Erase( nId) ; return true ; } //---------------------------------------------------------------------------- bool MachMgr::RemoveAllOperations( bool bExceptFirstDisp) { // indice terminazione ciclo int nStopId = ( bExceptFirstDisp ? GetFirstOperation() : GDB_ID_NULL) ; // rimuovo tutte le operazioni a partire dalla fine int nOperId = GetLastOperation() ; while ( nOperId != nStopId) { RemoveOperation( nOperId) ; nOperId = GetLastOperation() ; } return true ; } //---------------------------------------------------------------------------- // 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( 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( 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( 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( 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( 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( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // imposto la geometria return pMch->SetGeometry( vIds) ; } //---------------------------------------------------------------------------- bool MachMgr::MachiningApply( void) { // recupero la lavorazione corrente int nCurrMchId = GetCurrMachining() ; if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // imposto la geometria return pMch->Apply() ; } //---------------------------------------------------------------------------- bool MachMgr::GetMachiningParam( int nType, bool& bVal) const { // recupero la lavorazione corrente int nCurrMchId = GetCurrMachining() ; if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // recupero il parametro return pMch->GetParam( nType, bVal) ; } //---------------------------------------------------------------------------- bool MachMgr::GetMachiningParam( int nType, int& nVal) const { // recupero la lavorazione corrente int nCurrMchId = GetCurrMachining() ; if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // recupero il parametro return pMch->GetParam( nType, nVal) ; } //---------------------------------------------------------------------------- bool MachMgr::GetMachiningParam( int nType, double& dVal) const { // recupero la lavorazione corrente int nCurrMchId = GetCurrMachining() ; if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // recupero il parametro return pMch->GetParam( nType, dVal) ; } //---------------------------------------------------------------------------- bool MachMgr::GetMachiningParam( int nType, string& sVal) const { // recupero la lavorazione corrente int nCurrMchId = GetCurrMachining() ; if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // recupero il parametro return pMch->GetParam( nType, sVal) ; } //---------------------------------------------------------------------------- const ToolData* MachMgr::GetMachiningToolData( void) const { // recupero la lavorazione corrente int nCurrMchId = GetCurrMachining() ; if ( nCurrMchId == GDB_ID_NULL) return nullptr ; // ne recupero il gestore Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return nullptr ; // recupero il parametro return &( pMch->GetToolData()) ; }