//---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- // File : MachMgrFixtures.cpp Data : 13.05.15 Versione : 1.6e6 // Contenuto : Implementazione gestione ventose e morse della classe MachMgr. // // // // Modifiche : 13.05.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/EGnFileUtils.h" #include "/EgtDev/Include/EgtPointerOwner.h" using namespace std ; //---------------------------------------------------------------------------- bool MachMgr::SetTable( const string& sTable) { // imposto la tavola per la prima disposizione ( e il calcolo) Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( GetFirstOperation())) ; return ( pDisp != nullptr && pDisp->SetTable( sTable) && pDisp->ResetAreaOffset()) ; } //---------------------------------------------------------------------------- bool MachMgr::GetTable( string& sTable) const { // recupero la prima operazione, deve essere la prima disposizione Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( GetFirstOperation())) ; if ( pDisp == nullptr) return false ; // recupero la tavola return pDisp->GetTable( sTable) ; } //---------------------------------------------------------------------------- bool MachMgr::ChangeTable( const string& sTable, bool bUpdateDisp) { bool bOk = true ; // imposto la tavola per tutte le disposizioni ( e il calcolo) for ( int nPhase = 1 ; nPhase <= GetPhaseCount() && bOk ; ++ nPhase) { Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( GetPhaseDisposition( nPhase))) ; if ( pDisp != nullptr && pDisp->Init( this) && pDisp->SetTable( sTable) && pDisp->ResetAreaOffset()) { if ( bUpdateDisp) bOk = SetCurrPhase( nPhase, true) && bOk ; } else bOk = false ; } SetCurrPhase( 1) ; return bOk ; } //---------------------------------------------------------------------------- bool MachMgr::GetTableRef( int nInd, Point3d& ptPos) const { // attualmente previsto solo il riferimento 1 if ( nInd != 1) return false ; // recupero la prima operazione, deve essere la prima disposizione Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( GetFirstOperation())) ; if ( pDisp == nullptr) return false ; // recupero il punto return pDisp->GetTableRef1( ptPos) ; } //---------------------------------------------------------------------------- bool MachMgr::GetTableArea( int nInd, BBox3d& b3Area1) const { // attualmente prevista solo l'area 1 if ( nInd != 1) return false ; // recupero la prima operazione, deve essere la prima disposizione Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( GetFirstOperation())) ; if ( pDisp == nullptr) return false ; // recupero il bounding box return pDisp->GetTableArea1( b3Area1) ; } //---------------------------------------------------------------------------- bool MachMgr::SetTableAreaOffset( double dOffsXP, double dOffsYP, double dOffsXM, double dOffsYM) { // imposto l'offset dell'area della tavola per la fase corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( GetPhaseDisposition( m_nCurrPhase))) ; return ( pDisp != nullptr && pDisp->SetAreaOffset( dOffsXP, dOffsYP, dOffsXM, dOffsYM)) ; } //---------------------------------------------------------------------------- bool MachMgr::GetTableAreaOffset( int nInd, BBox3d& b3AreaOffs1) const { // attualmente prevista solo l'area 1 if ( nInd != 1) return false ; // recupero la disposizione della fase corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( GetPhaseDisposition( m_nCurrPhase))) ; if ( pDisp == nullptr) return false ; // recupero il bounding box return pDisp->GetTableAreaOffset1( b3AreaOffs1) ; } //---------------------------------------------------------------------------- bool MachMgr::ShowOnlyTable( bool bVal) { // verifico DB geometrico if ( m_pGeomDB == nullptr) return false ; // recupero la macchina corrente Machine* pMch = GetCurrMachine() ; if ( pMch == nullptr) return false ; // imposto visualizzazione della sola tavola o di tutto return pMch->SetLook( bVal ? MCH_LOOK_TAB : MCH_LOOK_ALL) ; } //---------------------------------------------------------------------------- bool MachMgr::MoveDispAxis( const string& sName, double dPos) { // recupero l'oggetto disposizione corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return GDB_ID_NULL ; // eseguo l'operazione return pDisp->MoveAxis( sName, dPos) ; } //---------------------------------------------------------------------------- bool MachMgr::RemoveDispAxis( const string& sName) { // recupero l'oggetto disposizione corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return GDB_ID_NULL ; // eseguo l'operazione return pDisp->RemoveAxis( sName) ; } //---------------------------------------------------------------------------- bool MachMgr::KeepAllDispAxes( int nSouPhase) { // se fase di origine non definita o uguale alla corrente, esco con successo if ( nSouPhase == 0 || nSouPhase == m_nCurrPhase) return true ; // copio il posizionamento Disposition* pSouDisp = GetDisposition( m_pGeomDB->GetUserObj( GetPhaseDisposition( nSouPhase))) ; Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( GetPhaseDisposition( m_nCurrPhase))) ; if ( pSouDisp == nullptr || pDisp == nullptr) return false ; for ( int i = 0 ; ; ++ i) { string sName ; double dPos ; if ( pSouDisp->GetMoveAxisData( i, sName, dPos)) pDisp->MoveAxis( sName, dPos) ; else break ; } return true ; } //---------------------------------------------------------------------------- int MachMgr::AddFixture( const string& sName, const Point3d& ptPos, double dAngRotDeg, double dMov) { // recupero l'oggetto disposizione corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return GDB_ID_NULL ; // eseguo l'operazione return pDisp->AddFixture( sName, GDB_ID_NULL, ptPos, dAngRotDeg, dMov) ; } //---------------------------------------------------------------------------- bool MachMgr::KeepFixture( int nFxtId, int nSouPhase) { // verifico validità e recupero fasi in cui è presente INTVECTOR vPhase ; if ( ! GetFixturePhases( nFxtId, vPhase)) return false ; // se fase corrente già presente, non devo fare alcunché if ( find( vPhase.begin(), vPhase.end(), m_nCurrPhase) != vPhase.end()) return true ; // se fase di origine non definita o uguale alla corrente, esco con successo if ( nSouPhase == 0 || nSouPhase == m_nCurrPhase) return true ; // copio il posizionamento Disposition* pSouDisp = GetDisposition( m_pGeomDB->GetUserObj( GetPhaseDisposition( nSouPhase))) ; Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( GetPhaseDisposition( m_nCurrPhase))) ; if ( pSouDisp == nullptr || pDisp == nullptr) return false ; for ( int i = 0 ; ; ++ i) { string sName ; int nId ; Point3d ptPos ; double dAngDeg ; double dMov ; string sTaLink ; if ( pSouDisp->GetFixtureData( i, sName, nId, ptPos, dAngDeg, dMov, sTaLink)) { if ( nId == nFxtId) { pDisp->AddFixture( sName, nId, ptPos, dAngDeg, dMov) ; pDisp->SetFixtureLink( nId, sTaLink) ; break ; } } else break ; } return true ; } //---------------------------------------------------------------------------- bool MachMgr::RemoveFixture( int nFxtId) { // recupero l'oggetto disposizione corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return false ; // eseguo l'operazione return pDisp->RemoveFixture( nFxtId) ; } //---------------------------------------------------------------------------- bool MachMgr::VerifyFixture( int nFxtId) const { // verifica validità bloccaggio if ( ! VerifyFixtureInGroup( nFxtId, false)) return false ; // recupero fasi in cui è presente INTVECTOR vPhase ; if ( ! GetFixturePhases( nFxtId, vPhase)) return false ; return ( find( vPhase.begin(), vPhase.end(), m_nCurrPhase) != vPhase.end()) ; } //---------------------------------------------------------------------------- int MachMgr::GetFirstFixture( void) const { // recupero l'oggetto disposizione corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return GDB_ID_NULL ; // eseguo l'operazione return pDisp->GetFirstFixture() ; } //---------------------------------------------------------------------------- int MachMgr::GetNextFixture( int nFxtId) const { // recupero l'oggetto disposizione corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return GDB_ID_NULL ; // eseguo l'operazione return pDisp->GetNextFixture( nFxtId) ; } //---------------------------------------------------------------------------- bool MachMgr::MoveFixture( int nId, const Vector3d& vtMove) { // recupero l'oggetto disposizione corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return false ; // eseguo l'operazione return pDisp->MoveFixture( nId, vtMove) ; } //---------------------------------------------------------------------------- bool MachMgr::RotateFixture( int nId, double dDeltaAngDeg) { // recupero l'oggetto disposizione corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return false ; // eseguo l'operazione return pDisp->RotateFixture( nId, dDeltaAngDeg) ; } //---------------------------------------------------------------------------- bool MachMgr::SetFixtureLink( int nId, const string& sTaLink) { // recupero l'oggetto disposizione corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return false ; // eseguo l'operazione return pDisp->SetFixtureLink( nId, sTaLink) ; } //---------------------------------------------------------------------------- bool MachMgr::MoveFixtureMobile( int nId, double dDeltaMov) { // recupero l'oggetto disposizione corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return false ; // eseguo l'operazione return pDisp->MoveFixtureMobile( nId, dDeltaMov) ; } //---------------------------------------------------------------------------- bool MachMgr::SetFixtureMobile( int nId, double dMov) { // recupero l'oggetto disposizione corrente Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return false ; // eseguo l'operazione return pDisp->SetFixtureMobile( nId, dMov) ; } //---------------------------------------------------------------------------- bool MachMgr::VerifyFixtureInGroup( int nFxtId, bool bLinkedAllowed) const { // se il bloccaggio fa parte del gruppo dei bloccaggi, va bene int nFxtGroupId = GetCurrFixtGroupId() ; if ( nFxtGroupId != GDB_ID_NULL && m_pGeomDB->GetParentId( nFxtId) == nFxtGroupId) return true ; // se consentito linkaggio ed il bloccaggio è linkato ad un gruppo della macchina corrente, va bene if ( bLinkedAllowed) { Machine* pMch = GetCurrMachine() ; if ( pMch != nullptr && pMch->IsLinkedFixture( nFxtId)) return true ; } // altrimenti errore return false ; } //---------------------------------------------------------------------------- bool MachMgr::GetFixturePhases( int nFxtId, INTVECTOR& vPhase) const { // pulisco parametro di ritorno vPhase.clear() ; // verifica validità bloccaggio if ( ! VerifyFixtureInGroup( nFxtId)) return false ; // recupero le fasi in cui è presente la fixture (se manca è non usata) m_pGeomDB->GetInfo( nFxtId, MACH_FXT_PHASE, vPhase) ; return true ; } //---------------------------------------------------------------------------- int MachMgr::GetUnusedFixture( const string& sName, int nPhase) const { // Verifico validità nome if ( IsEmptyOrSpaces( sName)) return false ; // Recupero il gruppo dei bloccaggi int nFxtGroupId = GetCurrFixtGroupId() ; // Cerco i bloccaggi non usati nella fase indicata int nId = m_pGeomDB->GetFirstNameInGroup( nFxtGroupId, sName) ; while ( nId != GDB_ID_NULL) { // recupero le fasi in cui è già usato INTVECTOR vPhase ; m_pGeomDB->GetInfo( nId, MACH_FXT_PHASE, vPhase) ; // se non c'è la fase corrente, è libero if ( find( vPhase.begin(), vPhase.end(), nPhase) == vPhase.end()) return nId ; // passo al successivo nId = m_pGeomDB->GetNextName( nId, sName) ; } // non trovato return GDB_ID_NULL ; } //---------------------------------------------------------------------------- bool MachMgr::IsUnusedFixture( int nId, int nPhase) const { // Recupero il gruppo dei bloccaggi int nFxtGroupId = GetCurrFixtGroupId() ; // Verifico appartenga al gruppo dei bloccaggi if ( m_pGeomDB->GetParentId( nId) != nFxtGroupId) return false ; // Verifico non sia usata nella fase indicata // recupero le fasi in cui è già usato INTVECTOR vPhase ; m_pGeomDB->GetInfo( nId, MACH_FXT_PHASE, vPhase) ; // se non c'è la fase corrente, è libero if ( find( vPhase.begin(), vPhase.end(), nPhase) == vPhase.end()) return true ; // già usato return false ; }