//---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- // File : API_GdbPartLayers.cpp Data : 29.01.15 Versione : 1.6a7 // Contenuto : Funzioni di gestione pezzi e layer relativi. // // // // Modifiche : 29.01.15 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "API.h" #include "API_Macro.h" #include "/EgtDev/Include/EInAPI.h" #include "/EgtDev/Include/EGkStringUtils3d.h" using namespace std ; //------------------------------------------------------------------------------- static bool EgtIsVisibleObj( IGeomDB* pGeomDB, int nId) { int nStat ; return ( pGeomDB->GetCalcStatus( nId, nStat) && nStat != GDB_ST_OFF) ; } //------------------------------------------------------------------------------- static int EgtVerifyOrNextVisible( IGeomDB* pGeomDB, int nId) { while ( nId != GDB_ID_NULL) { if ( EgtIsVisibleObj( pGeomDB, nId)) return nId ; nId = pGeomDB->GetNextGroup( nId) ; } return GDB_ID_NULL ; } //------------------------------------------------------------------------------- int __stdcall EgtGetCurrPart( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, GDB_ID_NULL) // recupero il pezzo corrente return pGseCtx->m_nCurrPart ; } //------------------------------------------------------------------------------- int __stdcall EgtGetCurrLayer( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, GDB_ID_NULL) // recupero il pezzo corrente return pGseCtx->m_nCurrLayer ; } //------------------------------------------------------------------------------- BOOL __stdcall EgtSetCurrPartLayer( int nPartId, int nLayerId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, FALSE) IGeomDB* pGeomDB = pGseCtx->m_pGeomDB ; bool bOk = true ; // verifico validità e visibilità pezzo if ( pGeomDB->GetParentId( nPartId) == GDB_ID_ROOT && EgtIsVisibleObj( pGeomDB, nPartId)) { if ( nPartId != pGseCtx->m_nCurrPart) pGseCtx->m_nCurrLayer = GDB_ID_NULL ; pGseCtx->m_nCurrPart = nPartId ; } else { if ( nPartId == pGseCtx->m_nCurrPart || nPartId == GDB_ID_NULL) { pGseCtx->m_nCurrPart = GDB_ID_NULL ; pGseCtx->m_nCurrLayer = GDB_ID_NULL ; } bOk = false ; } // verifico validità e visibilità layer if ( pGeomDB->GetParentId( nLayerId) == nPartId && EgtIsVisibleObj( pGeomDB, nLayerId)) { pGseCtx->m_nCurrLayer = nLayerId ; } else { if ( nLayerId == pGseCtx->m_nCurrLayer || nLayerId == GDB_ID_NULL) pGseCtx->m_nCurrLayer = GDB_ID_NULL ; bOk = false ; } // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtSetCurrPartLayer(" + ToString( nPartId) + "," + ToString( nLayerId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return ( bOk ? TRUE : FALSE) ; } //------------------------------------------------------------------------------- BOOL __stdcall EgtResetCurrPartLayer( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, FALSE) IGeomDB* pGeomDB = pGseCtx->m_pGeomDB ; // reset pGseCtx->m_nCurrPart = GDB_ID_NULL ; pGseCtx->m_nCurrLayer = GDB_ID_NULL ; // cerco il primo pezzo con un layer visibile int nPartId = EgtGetFirstVisiblePart() ; while ( nPartId != GDB_ID_NULL) { // cerco il primo layer visibile del pezzo int nLayerId = EgtGetFirstVisibleLayer( nPartId) ; if ( nLayerId != GDB_ID_NULL) { // assegno il pezzo corrente pGseCtx->m_nCurrPart = nPartId ; // assegno il layer corrente pGseCtx->m_nCurrLayer = nLayerId ; // esco dal ciclo di ricerca break ; } nPartId = EgtGetNextVisiblePart( nPartId) ; } // se non ho trovato layer visibile mi accontento del primo pezzo visibile if ( pGseCtx->m_nCurrPart == GDB_ID_NULL) pGseCtx->m_nCurrPart = EgtGetFirstVisiblePart() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtResetCurrPartLayer()" " -- Ids=" + ToString( pGseCtx->m_nCurrPart) + "," + ToString( pGseCtx->m_nCurrLayer) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return TRUE ; } //------------------------------------------------------------------------------- int __stdcall EgtGetFirstVisiblePart( void) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // recupero il primo gruppo sotto la radice int nPartId = pGeomDB->GetFirstGroupInGroup( GDB_ID_ROOT) ; // verifico sia visibile oppure passo al primo successivo visibile return EgtVerifyOrNextVisible( pGeomDB, nPartId) ; } //------------------------------------------------------------------------------- int __stdcall EgtGetNextVisiblePart( int nId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // recupero il successivo gruppo int nPartId = pGeomDB->GetNextGroup( nId) ; // verifico sia visibile oppure passo al primo successivo visibile return EgtVerifyOrNextVisible( pGeomDB, nPartId) ; } //------------------------------------------------------------------------------- int __stdcall EgtGetFirstVisibleLayer( int nPartId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // verifico la visibilità del pezzo if ( ! EgtIsVisibleObj( pGeomDB, nPartId)) return GDB_ID_NULL ; // recupero il primo layer nel pezzo int nLayerId = pGeomDB->GetFirstGroupInGroup( nPartId) ; // verifico sia visibile oppure passo al primo successivo visibile return EgtVerifyOrNextVisible( pGeomDB, nLayerId) ; } //------------------------------------------------------------------------------- int __stdcall EgtGetNextVisibleLayer( int nId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // recupero il successivo gruppo int nLayerId = pGeomDB->GetNextGroup( nId) ; // verifico sia visibile oppure passo al primo successivo visibile return EgtVerifyOrNextVisible( pGeomDB, nLayerId) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSelectPartObjs( int nPartId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) bool bOk = true ; // verifico sia veramente un pezzo (gruppo sotto la radice) if ( pGeomDB->GetGdbType( nPartId) == GDB_TY_GROUP && pGeomDB->GetParentId( nPartId) == GDB_ID_ROOT) { // ciclo sugli oggetti del pezzo int nId = pGeomDB->GetFirstInGroup( nPartId) ; while ( nId != GDB_ID_NULL) { // se è gruppo seleziono i suoi componenti if ( pGeomDB->GetGdbType( nId) == GDB_TY_GROUP) pGeomDB->SelectGroupObjs( nId) ; // altrimenti lo seleziono direttamente else pGeomDB->SelectObj( nId) ; // passo al successivo nId = pGeomDB->GetNext( nId) ; } } else bOk = false ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtSelectPartObjs(" + ToString( nPartId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return ( bOk ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtDeselectPartObjs( int nPartId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) bool bOk = true ; // verifico sia veramente un pezzo (gruppo sotto la radice) if ( pGeomDB->GetGdbType( nPartId) == GDB_TY_GROUP && pGeomDB->GetParentId( nPartId) == GDB_ID_ROOT) { // ciclo sugli oggetti del pezzo int nId = pGeomDB->GetFirstInGroup( nPartId) ; while ( nId != GDB_ID_NULL) { // se è gruppo deseleziono i suoi componenti if ( pGeomDB->GetGdbType( nId) == GDB_TY_GROUP) pGeomDB->DeselectGroupObjs( nId) ; // altrimenti lo deseleziono direttamente else pGeomDB->DeselectObj( nId) ; // passo al successivo nId = pGeomDB->GetNext( nId) ; } } else bOk = false ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtDeselectPartObjs(" + ToString( nPartId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return ( bOk ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSelectLayerObjs( int nLayerId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) bool bOk = true ; // verifico sia veramente un layer (gruppo senza sottogruppi) if ( pGeomDB->GetGdbType( nLayerId) == GDB_TY_GROUP && pGeomDB->GetFirstGroupInGroup( nLayerId) == GDB_ID_NULL) { // ciclo sugli oggetti del layer int nId = pGeomDB->GetFirstInGroup( nLayerId) ; while ( nId != GDB_ID_NULL) { // seleziono pGeomDB->SelectObj( nId) ; // passo al successivo nId = pGeomDB->GetNext( nId) ; } } else bOk = false ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtSelectLayerObjs(" + ToString( nLayerId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return ( bOk ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtDeselectLayerObjs( int nLayerId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) bool bOk = true ; // verifico sia veramente un layer (gruppo senza sottogruppi) if ( pGeomDB->GetGdbType( nLayerId) == GDB_TY_GROUP && pGeomDB->GetFirstGroupInGroup( nLayerId) == GDB_ID_NULL) { // ciclo sugli oggetti del layer int nId = pGeomDB->GetFirstInGroup( nLayerId) ; while ( nId != GDB_ID_NULL) { // deseleziono pGeomDB->DeselectObj( nId) ; // passo al successivo nId = pGeomDB->GetNext( nId) ; } } else bOk = false ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtDeselectLayerObjs(" + ToString( nLayerId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return ( bOk ? TRUE : FALSE) ; }